XSD newbie: Element based choice.

B

BLUE

Suppose I have an XML file like this:

<type>...</type>
<positionID>...</positionID>
<category>...</category>


I want to specify in my XML Schema that:

- if "type" is "One" I must have
<positionID>A_STRING</positionID>

- if "type" is "Two" I must have
<positionID>
<zoneID>A_POSITIVE_NUM</zoneID>
<sectorID>A_POSITIVE_NUM</sectorID>
<cellID>A_POSITIVE_NUM</cellID>
</positionID>

- if "type" is "Three" I must have
no category or empty category

- if "type" is "Four" I must have
the same thing as for case "Two" and "Three"


If this is not possible can I check this from my application or it would be
a semantic error and it would be better to separate the two schemas?


Thank you for any help!
Luigi.
 
J

John Saunders

BLUE said:
Suppose I have an XML file like this:

<type>...</type>
<positionID>...</positionID>
<category>...</category>

That's not a well-formed XML document. You need root element around all of
those.
I want to specify in my XML Schema that:

- if "type" is "One" I must have
<positionID>A_STRING</positionID>

- if "type" is "Two" I must have
<positionID>
<zoneID>A_POSITIVE_NUM</zoneID>
<sectorID>A_POSITIVE_NUM</sectorID>
<cellID>A_POSITIVE_NUM</cellID>
</positionID>

- if "type" is "Three" I must have
no category or empty category

- if "type" is "Four" I must have
the same thing as for case "Two" and "Three"


If this is not possible can I check this from my application or it would
be a semantic error and it would be better to separate the two schemas?

XML Schema cannot describe this situation. You'll have to check yourself.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,008
Messages
2,570,268
Members
46,867
Latest member
Lonny Petersen

Latest Threads

Top