tags:

views:

226

answers:

1

I'm trying to create a type in an XML schema to enforce an element with both:

  • A single attribute; and
  • Simple content matching an enumeration.

In an XML document, the element might look like:

<Operator Permutation="true">
  Equals
</Operator>

Where "Equals" would be one of the enumerations.

Is this possible? If so, how?

I've tried doing in in XMLSpy with no success. If I make a simple type, it only allows content enumeraions without attributes. If I make a complex type, it only allows attributes without content enumerations.

Edit: Thanks, David. That works perfectly, but I just added this inside the restriction so the validation ignores line breaks:

<xs:whiteSpace value="collapse"/>
+1  A: 

How about

  <xs:element name="Operator" type="MixedElement" />

  <xs:complexType name="MixedElement">
    <xs:simpleContent>
      <xs:extension base="EnumType">
        <xs:attribute name="Permutation" type="xs:boolean">
        </xs:attribute>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <xs:simpleType name="EnumType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Equals"/>
      <xs:enumeration value="NotEquals"/>
    </xs:restriction>
  </xs:simpleType>
David Norman