Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSD newbie: Element based choice.

Reply
Thread Tools

XSD newbie: Element based choice.

 
 
BLUE
Guest
Posts: n/a
 
      03-23-2007
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.


 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      03-23-2007
"BLUE" <blue> wrote in message
news:460446d5$0$37193$(E-Mail Removed) ...
> 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


 
Reply With Quote
 
 
 
 
Priya Lakshminarayanan
Guest
Posts: n/a
 
      03-29-2007
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$(E-Mail Removed) ...
> 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.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSD restriction of nesting an element within another element with aspecific attribute value? PeteOlcott XML 1 02-05-2009 06:39 AM
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
XPath expression for element based on content of other element withsame parent Ian Wilson XML 2 07-26-2007 04:11 PM
XML + XSD: Is it possible to get all errors against the XSD? Markus Java 1 11-22-2005 02:53 PM
XSD - element, element value and attribute ? Matthet XML 2 09-24-2003 04:10 PM



Advertisments