I have an XML Schema that looks like this:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="A" minOccurs="0" maxOccurs="1"/>
<xs:element name="B" minOccurs="0" maxOccurs="1"/>
<xs:element name="C" minOccurs="0" maxOccurs="32"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The following is valid according to this schema:
<root xsi:noNamespaceSchemaLocation="MySchema.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
</root>
However, I'd like to make the above XML invalid.
More specifically, I'd like to require:
1. that the <root>
have at least one child element, be it an <A>
, a <B>
, or a <C>
, and
2. that the <root>
have at most one <A>
child, and at most one <B>
child.
Suggestions?
Solution is:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:choice>
<xs:sequence>
<xs:element name="A"/>
<xs:element name="B" minOccurs="0"/>
<xs:element name="C" minOccurs="0" maxOccurs="32"/>
</xs:sequence>
<xs:sequence>
<xs:element name="B"/>
<xs:element name="C" minOccurs="0" maxOccurs="32"/>
</xs:sequence>
<xs:sequence>
<xs:element name="C" minOccurs="1" maxOccurs="32"/>
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>