Page 1 of 1

Validating unordered elements with additional requirements

Posted: Wed Jan 19, 2005 1:49 am
by SwimsZoots
Hi,

I have to validate an XML document where there is a parent element <Output>, which, if present must have one or both of the following child elements: <errors>, <mappings>. (max. 1 instance each, unordered).

Any ideas on what as possible schema would look like, if it is possible at all?

tia,
bob

Try this

Posted: Wed Jan 19, 2005 5:16 pm
by Radu
Hello

Maybe try would work:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="output">
<xs:complexType>
<xs:choice>
<xs:sequence>
<xs:element ref="errors" minOccurs="1" maxOccurs="1"/>
<xs:element ref="mappings" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:sequence>
<xs:element ref="mappings" minOccurs="1" maxOccurs="1"/>
<xs:element ref="errors" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="errors"/>
<xs:element name="mappings"/>
</xs:schema>

Posted: Wed Jan 19, 2005 10:07 pm
by SwimsZoots
Thanks a bunch. This helps a lot. Plus it gives me some ideas for other things I need to do.