Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSD question 1

Status
Not open for further replies.

zeert2002

Programmer
Sep 26, 2007
13
0
0
US
Hi, I have a question regarding XSD. I have this format in my xsd:

<xs:element name="someName">
<xs:complexType>
<xs:sequence>
<xs:element ref="id"/>
<xs:element ref="firstName"/>
<xs:element ref="lastName"/>
</xs:sequence>
</xs:complexType>
</xs:element>

So this xml is good:

<someName>
<id>43</id>
<firstName>first name</firstName>
<lastName> last name</lastName>
</someName>

However, if the firstName and lastName element is switched around like this:

<someName>
<id>43</id>
<lastName> last name</lastName>
<firstName>first name</firstName>
</someName>

Then the schema will not recognize it. Is there a way to allow any ordering? Thanks a lot.
 
When you put something in a sequence, they must appear - funnily enough - sequentially. Use [tt]xs:all[/tt] instead.

Code:
<xs:element name="someName">
  <xs:complexType>
    <xs:all>
      <xs:element ref="id"/>
      <xs:element ref="firstName"/>
      <xs:element ref="lastName"/>
    </xs:all>
  </xs:complexType>
</xs:element>

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

Webflo
 
Sorry, but I have another question. My question now is what is the syntax to make it so that the minoccur on the id is 2 and the order doesn't matter. I tried doing this but it gave me an error. Thanks.

<xs:element name="someName">
<xs:complexType>
<xs:all>
<xs:element ref="id"/ minOccur="2">
<xs:element ref="firstName"/>
<xs:element ref="lastName"/>
</xs:all>
</xs:complexType>
</xs:element>

I know that minOccur should only be 0 or 1 for xs:all. But is there a way around this? Thanks so much again.
 
Code:
<xs:element name="someName">
  <xs:complexType>
    <xs:all>
      <xs:element ref="id"/ minOccur[b][COLOR=red]s[/color][/b]="2">
      <xs:element ref="firstName"/>
      <xs:element ref="lastName"/>
    </xs:all>
  </xs:complexType>
</xs:element>

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

Webflo
 
I tried what you typed but it gave me an error stating that minOccurs is equal to 0 or 1. These are the only two allowable values. Thanks for replying.
 
You've to wrap the element id within a single containing element. The arbitrary order is thereby also limited.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top