?
Solved

Schema validation and order of elements

Posted on 2001-09-14
4
Medium Priority
?
427 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 300 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

Not sure which OpenStack Certification to get?

So you’ve realized you might want to get certified in OpenStack, but you’re not sure what the benefits might be or even which one you should take. You know there are several certification courses you can choose from, but how do you know which one is right for you?

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

762 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