Solved

Schema validation and order of elements

Posted on 2001-09-14
4
385 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
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 learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now