Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Get exactly one choice element

Reply
Thread Tools

Get exactly one choice element

 
 
Mario
Guest
Posts: n/a
 
      12-01-2004
Hi;

I try to limit the selection of elements to exactly one. I have to do
it by using elements, attributes are no alternativ.
If I use the configuration shown below, it is also possible to select
no element. If I set minOccurs to 1 at both elements, I have to select
both. How I can can define that just one and no more than one element
are allowed?

Thx for your help!


If I have the following xsd:
----------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlnss="http://www.w3.org/2001/XMLSchema">
<xs:element name="test">
<xs:complexType>
<xs:choice>
<xs:element name="element1" minOccurs="0"/>
<xs:element name="element2" minOccurs="0"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

and the following xml should not be allowed:
-----------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<test xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="schematest.xsd">
</test>
 
Reply With Quote
 
 
 
 
Priscilla Walmsley
Guest
Posts: n/a
 
      12-03-2004
Hi,

If you use minOccurs="1", you don't need to have both elements present.
Because you're using the <choice> group, it's a choice of one (and only
one) of those elements.


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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
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
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
c++ as choice for long term application choice. miles.jg C++ 16 11-14-2007 03:43 PM
Can Choice components respond to keyboard input like HTML Choice components? Mickey Segal Java 0 02-02-2004 10:59 PM
Choice of DHCP-server? Is the "IOS-one" a good choice? Fred Cisco 1 12-11-2003 06:25 AM
In Schema, how to say "If one element exist, another element must exist"? Y.S. XML 3 09-17-2003 02:51 PM



Advertisments
 



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