Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > How do I allow both elements or No elements

Reply
Thread Tools

How do I allow both elements or No elements

 
 
Billy
Guest
Posts: n/a
 
      09-09-2005
I have a current xsd that allows the xml to have 0..1 chassisid element
and 0..1 terminalid element. But now I want to restrict these elements
in a way that either both chassisid and terminalid are supplied or
neither are supplies never just one of the elements is ever supplied.
I believe this can be done but the restriction I have is that I cannot
change the structure of the xml file, i.e. by nesting a new section for
chassisid/terminalid.

e.g.

xsd:
....
<xs:element name="chassisid" type="xs:string" minOccurs="0"
maxOccurs="1"/>
<xs:element name="terminalid" type="xs:string" minOccurs="0"
maxOccurs="1"/>
....

xml:
....
<chassisid>A123456789</chassisid>
<terminalid>A2345678</terminalid>
....

If you can help then many thanks.

Regards

Billy

 
Reply With Quote
 
 
 
 
Priscilla Walmsley
Guest
Posts: n/a
 
      09-09-2005
How about:

<xs:sequence minOccurs="0" maxOccurs="1">
<xs:element name="chassisid" type="xs:string"/>
<xs:element name="terminalid" type="xs:string"/>
</xs:sequence>

Hope that helps,
Priscilla

----------------------------------
Priscilla Walmsley
Author, Definitive XML Schema
http://www.datypic.com
----------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Klaus Johannes Rusch
Guest
Posts: n/a
 
      09-09-2005
Billy wrote:
> I have a current xsd that allows the xml to have 0..1 chassisid element
> and 0..1 terminalid element. But now I want to restrict these elements
> in a way that either both chassisid and terminalid are supplied or
> neither are supplies never just one of the elements is ever supplied.


<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="1">
<xs:element ref="chassisid"/>
<xs:element ref="terminalid"/>
</xs:sequence>
</xs:complexType>

--
Klaus Johannes Rusch
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.atmedia.net/KlausRusch/
 
Reply With Quote
 
Billy boy
Guest
Posts: n/a
 
      09-11-2005
Thanks for your time,

It looks pretty simple and unsure why I haven't tried that already. I
will try it Monday when I get back to work.

Once again, thanks

Billy



*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
Billy
Guest
Posts: n/a
 
      09-12-2005
It works a treat, many thanks Priscilla & Klaus.

Billy

 
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
XML Schema (XSD): allow an attribute OR a sub-element NOT BOTH Eric XML 4 03-07-2007 11:16 PM
newbie: allow deny vs deny allow Jeff ASP .Net 2 09-19-2006 02:12 AM
To allow left click only on some elements of web page NOT all elements vikas.khengare@gmail.com Javascript 1 05-31-2006 09:26 AM
Allow Traceroutes Out to internet, no Pings/traces in. On Both PIX and 2610 Scott Townsend Cisco 3 10-08-2004 09:59 PM
Location element in the Web.config file. Allow System Admin whole directory, allow others specific page Ryan Taylor ASP .Net Security 1 09-09-2004 06:52 PM



Advertisments