I am trying to understand example from w3 school about sequence element. I thought that element inside the sequence can show only once but example from w3 school lead me to believe otherwise. This is example...
<xs:element name="pets">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="dog" type="xs:string"/>
<xs:element name="cat" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
So explanation on w3 schools says that "This example shows a declaration for an element called "pets" that can have zero or more of the following elements, dog and cat, in the sequence element". I tried to test that by doing this....
sorry second example i pasted by mistake....this is what i meant that wil not validate based on schema from the top...
<pets>
<dog>something</dog>
<dog>something else</dog>
<cat>else</cat>
</pets>
But validator gives me errors http://www.corefiling.com/opensource/schemaValidate.html. I would like to understand both examples. Sequence where it is allowable to have multiple of same elements and also where each element in sequence must be present and must show once only.
any examples and suggestions would be appreciated.
That schema allows the content to be zero or more repetitions of the sequence "<dog> followed by <cat>". In other words the pets element can be empty, or it can contain dog-cat, dog-cat-dog-cat, etc. but not dog-dog.
If you want any number of dog or cat elements in any combination then you probably want a choice instead of a sequence.
<xs:element name="pets">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="dog" type="xs:string"/>
<xs:element name="cat" type="xs:string"/>
</xs:choice>
</xs:complexType>
</xs:element>
This would allow zero or more repetitions of X, where X is either one dog or one cat element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With