Solved

Schema validation and order of elements

Posted on 2001-09-14
4
416 Views
Last Modified: 2013-11-19
I have a problem for validation an XML document using a schema. In fact, i've got an element that contain other elements. But the order of those elements is not important.
How should i build the schema ?
0
Comment
Question by:jguy
  • 3
4 Comments
 
LVL 4

Expert Comment

by:sdussinger
ID: 6482818
Try using xsd:all to define your container:

<xsd:complexType name="container">
  <xsd:all>
    <xsd:element name="anelement" type="xsd:string/>
    <xsd:element name="anotherelement" type="xsd:string"/>
  </xsd:all>
</xsd:complexType>

This would allow you to write containers as follows:

<container>
  <anelement>An Element</anelement>
  <anotherelement>Another Element></anotherelement>
</container>

 -or -

<container>
  <anotherelement>Another Element</anotherelement>
  <anelement>An Element</anelement>
</container>

HTH

--Steve
0
 
LVL 4

Expert Comment

by:sdussinger
ID: 6482931
The xsd:all solution works fine as long as all of the elements in the container occur once and only once (in any order). If some of the elements in the container are optional or may occur more than once, you can use this:

 <xsd:complexType name="container">
   <xsd:sequence>
    <xsd:choice maxOccurs="unbounded">
      <xsd:element name = "anelement" type="xsd:string"/>
      <xsd:element name = "anotherelement" type="xsd:string"/>
    </xsd:choice>
  </xsd:sequence>
 </xsd:complexType>

HTH

--Steve
0
 

Author Comment

by:jguy
ID: 6483058
ok

But what happen, my complex type inherite from an other complex type. The probleme that i have is that the elements defined in de inherited complexe type must be before the new elements.

Thanks
0
 
LVL 4

Accepted Solution

by:
sdussinger earned 100 total points
ID: 6483145
<xsd:complexType name="derivedContainer">
  <xsd:complexContent>
    <xsd:extension base="baseContainer">
      <xsd:sequence>
        <xsd:choice maxOccurs="unbounded">
          <xsd:element name="anelement" type="xsd:string"/>
          <xsd:element name="anotherelement" type="xsd:string"/>
        </xsd:choice>
      </xsd:sequence>
    </xsd:extension>
  </xsd:complexContent>
</xsd:complexType>

HTH

--Steve
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Re-position sub-options beneath the TAB 7 106
Convert XML to excel12book 5 33
XML response optional elements 12 55
Unexpected End of File 11 54
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question