Validating unordered elements with additional requirements

This should cover W3C XML Schema, Relax NG and DTD related problems.
SwimsZoots
Posts: 2
Joined: Wed Jan 19, 2005 1:28 am
Location: NJ
Contact:

Validating unordered elements with additional requirements

Post by SwimsZoots » Wed Jan 19, 2005 1:49 am

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

Radu
Posts: 6589
Joined: Fri Jul 09, 2004 5:18 pm

Try this

Post by Radu » Wed Jan 19, 2005 5:16 pm

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>

SwimsZoots
Posts: 2
Joined: Wed Jan 19, 2005 1:28 am
Location: NJ
Contact:

Post by SwimsZoots » Wed Jan 19, 2005 10:07 pm

Thanks a bunch. This helps a lot. Plus it gives me some ideas for other things I need to do.

Post Reply