Solved

Schema validation and order of elements

Posted on 2001-09-14
4
420 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
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…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

734 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