Validating unordered elements with additional requirements

This should cover W3C XML Schema, Relax NG and DTD related problems.
SwimsZoots
Posts: 2
Location: NJ

Validating unordered elements with additional requirements

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: 5563

Try this

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
Location: NJ

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.

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 1 guest