0
votes

I want to validate my xml using xsd. My requirement is I want to include some elements.

  1. Those elements can be take any order
  2. One element should be included exactly one time

It is not xs:choice suitable for me as the parent element has more than one of above elemts

The xml should be seen like follows:

<parent>
<child1></child1> // at least one time and only once
<child2></child2> // at least one time and only once //any order
</parent>

So my XSD should contain

element type="xs:int" name="....." minOccurs="1" maxOccurs="1"

I can't use sequence tag because it needs these child elements in sequence, cant use choice tag that allows only one child . Could you suggest me a way

1

1 Answers

0
votes

I found the answer: the xsd as follows

<xs:element name="parent">

                <xs:complexType>
                    <xs:choice maxOccurs="unbounded">
                        <xs:element type="xs:int" name="child1" minOccurs="1" maxOccurs="1">

                        </xs:element>
                        <xs:element type="xs:string" name="child2" minOccurs="1" maxOccurs="1">

                        </xs:element>

                     </xs:all>
                </xs:complexType>
            </xs:element>