XML Schema element validation order

This should cover W3C XML Schema, Relax NG and DTD related problems.
Posts: 1
Joined: Thu Apr 12, 2007 1:29 pm

XML Schema element validation order

Post by mirceaa » Thu Apr 12, 2007 1:30 pm


I'm following the example in the XML schema tutorial from the w3.org, however I can't understand the design method based on defining all elements and attributes first, and then referring to them using the ref attribute:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<!-- definition of simple elements -->
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>

<!-- definition of attributes
<xs:attribute name="orderid" type="xs:string"/>

<!-- definition of complex elements -->
<xs:element name="shipto">
<xs:element ref="name"/>
<xs:element ref="address"/>
<xs:element ref="city"/>
<xs:element ref="country"/>
<xs:element name="item">
<xs:element ref="title"/>
<xs:element ref="note" minOccurs="0"/>
<xs:element ref="quantity"/>
<xs:element ref="price"/>

<xs:element name="shiporder">
<xs:element ref="orderperson"/>
<xs:element ref="shipto"/>
ref="item" maxOccurs="unbounded"/>
<xs:attribute ref="orderid" use="required"/>


The question is how can I identify the desired root element of the target document? I can see from the example it's the "shiporder" element, but why not the "orderto" or "shipto" or "item" elements that are previously defined ?

Thank you !

Site Admin
Posts: 2102
Joined: Thu Jan 09, 2003 2:58 pm

Post by george » Thu Apr 12, 2007 11:14 pm

As you noticed XML Schema allows any global element to be a document root element for a document that can be valid against the schema. There is no mechanism in XML Schema to say that one or more elements are the elements that should be rott elements.

As a side note, Relax NG has a start pattern that defines what elements can be the root elements for valid documents.

Best Regards,
George Cristian Bina

Post Reply