How to ensure some mandatory and some optional elements under complextype in xml?

StephieY

New Member
I am facing problems in making a complex element, which allows both optional as well as mandatory elements.For the xml below, say h2 is mandatory, while h1 is optional, and the order does not matter.Case 1:\[code\]<root><h1/><h2/></root>\[/code\]Case 2:\[code\]<root><h2/></root>\[/code\]Case 3:\[code\]<root><h2/><h1/></root>\[/code\]XSD:\[code\]<xs:element name="root"> <xs:complexType> <xs:sequence minOccurs="1" maxOccurs="unbounded"> <xs:element name="h1" minOccurs="0"></xs:element> <xs:element name="h2" minOccurs="1" /> </xs:sequence> </xs:complexType></xs:element>\[/code\]the third case above fails in this xsd, but such case is valid.I need an xsd that is valid for all the above mentioned cases.
 
Back
Top