[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Schema validation and order of elements

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

656 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