XML Schema Structure for an Enumerated Type with Attributes
I'm trying to create a type in XML Schema to enforce an element with both:
- One attribute; and
- Simple content matching the enum.
In an XML document, an element might look like this:
<Operator Permutation="true">
Equals
</Operator>
Where "Equal" would be one of the enumerations.
Is it possible? If so, how?
I've tried doing in XMLSpy with no success. If I do a simple type, it only allows content enums without attributes. If I do a complex type it only allows attributes without content enums.
Edit: Thanks David. This works fine, but I just added this to the constraint, so the check ignores line breaks:
<xs:whiteSpace value="collapse"/>
+1
source to share
1 answer
What 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>
+1
source to share