Order definition in XML Schema

Go To StackoverFlow.com


I want to define that the first element will be of a specific type, and the following will be some elements in any order. Like this:

<!-- always at first -->

<!-- other nodes in any order-->

I can't use <xsd:sequence> because it will force all nodes to be in order.

Thanks for your help. Sorry on my english.

2012-04-04 17:11
by RoadBump


A good starting layout could look like this:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="node">
        <xs:element name="node-data"/>
        <xs:choice minOccurs="0" maxOccurs="unbounded">         
          <xs:element name="node3" />
          <xs:element name="node1" />
          <xs:element name="node2" />

You could then refine the types, add more nodes under the choice, etc. If you want to support wildcards, then use of xs:any would be required.

2012-04-04 17:18
by Petru Gardea
Thank you very much, it helped me. It's strange that the authors of xsd not gave a easier way to do this basic feature - RoadBump 2012-04-04 23:11