I have trouble to write XSD with these constraints: Name element is required; Value element could appear 0 or multiple times; Category element is optional. I now have XSD like this:
<xs:element name="Detail" maxOccurs="unbounded" minOccurs="0"> <!-- 0 or more Details -->
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="Name"/> <!-- Name element is required -->
<xs:element type="xs:string" name="Value" maxOccurs="unbounded" minOccurs="0"/> <!-- 0 or more occurences of Value element -->
<xs:element type="xs:string" name="Category" minOccurs="0" maxOccurs="1"/> <!-- optional (0 or 1) Category element -->
</xs:sequence>
</xs:complexType>
</xs:element>
The problem is that input XML may not follow the order in the schema. And xs:choice and xs:all have appearance constraint that are not good enough for me.
Can anyone help me to solve this problem that allow XML element in any order with any number of times appearance?
Attach a sample input XML:
<Detail>
<Category />
<Name> Thanks </Name>
<Value> 1 </Value>
<Value> 2 </Value>
</Detail>