Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   XSD newbie: Element based choice. (http://www.velocityreviews.com/forums/t486706-xsd-newbie-element-based-choice.html)

BLUE 03-23-2007 09:30 PM

XSD newbie: Element based choice.
 
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.



John Saunders 03-23-2007 11:15 PM

Re: XSD newbie: Element based choice.
 
"BLUE" <blue> wrote in message
news:460446d5$0$37193$4fafbaef@reader3.news.tin.it ...
> 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



Priya Lakshminarayanan 03-29-2007 06:29 PM

Re: XSD newbie: Element based choice.
 
These constraints are called co-occurrence constraints and cannot be
specified using XML Schema. You can embed Schematron rules in your schema to
specify the same.
For more information on Schematron, check the following:
http://xml.ascc.net/resource/schematron/
http://www.xml.com/pub/a/2000/11/22/schematron.html

Thanks,
Priya

"BLUE" <blue> wrote in message
news:460446d5$0$37193$4fafbaef@reader3.news.tin.it ...
> 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.
>





All times are GMT. The time now is 02:53 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57