XSD - controlling maxOccurs for nested elements, without enforcing sequence

utterstaisy

New Member
I wish to define an XSD that enforces the following rules...I have a parent1 element, which can have the following child elements child1, child2, and child3.
  • parent1 can have 0-1 of child1
  • parent1 can have 0-1 of child2
  • parent1 can have 0 - unbounded of child3
The order of the items is not important. E.g.\[quote\]\[code\]<parent1> <child3/> <child1/> <child2/> <child3/> <child3/></parent1>\[/code\]\[/quote\]I've gotten close, but no cigar. The closest I can get is the enforcing of the min and max occurs, but the order is enforced.\[quote\]\[code\]<xsd:element name="parent1" minOccurs="0" maxOccurs="unbounded"> <xsd:complexType> <xsd:sequence> <xsd:element name="child1" minOccurs="0" maxOccurs="1"/> <xsd:element name="child2" minOccurs="0" maxOccurs="1" /> <xsd:element name="child3" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType></xsd:element>\[/code\]\[/quote\]I've tried using all instead of sequence, but that limits maxOccurs to 1 for the child elements. I've also tried using choice with a maxOccurs to replace sequence, but that doesn't limit how many child1 or child2 elements you can have beneath parent1.
 
Back
Top