[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: XML Schema Question: specifying restrictions for a list of

  • To: 'Peter Loh Yoon Chao' <yoonchao@s...>, xml-dev@l...
  • Subject: RE: XML Schema Question: specifying restrictions for a list of elements
  • From: Tom Gaven <Tom.Gaven@e...>
  • Date: Wed, 7 Apr 2004 08:51:59 -0400

xml schema restrictions

Peter, I don't know if this can be done in XSD, but here is a RELAX NG
schema ( compact syntax ) that can handle it:

start  = computer_list
computer_list = element computer_list { computer*  &  computerDefault }
computer = element computer { computerNames }
computerDefault = element computer { attribute default { xsd:boolean },
computerNames }
computerNames =  'HP' | 'Dell' 

You can interleave ('&' connector) the single 'computer with default
attribute' with one or more 'computers without default attribute'.

Tom 

-----Original Message-----
From: Peter Loh Yoon Chao [mailto:yoonchao@s...] 
Sent: Wednesday, April 07, 2004 8:23 AM
To: xml-dev@l...
Subject:  XML Schema Question: specifying restrictions for a list
of elements


Hi,

I have the following construct in my XML document:

        <computer_list>
          <computer default="true">Dell</do_type>
          <computer>HP</do_type>
        </computer_list>

Only 1 of <computer> can have the "default" attribute set to true.  I am
trying to specify the corresponding XML schema to enforce this.  I tried the
following among other variations:

                    <xs:element name="computer_list">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element maxOccurs="unbounded" name="computer">
                            <xs:complexType>
                              <xs:simpleContent>
		        <xs:restriction base="xs:string">
		          <xs:enumeration value="Dell"/>
		          <xs:enumeration value="HP"/>
		        </xs:restriction>
                                <xs:extension base="xs:string">
                                  <xs:attribute name="default"
type="xs:boolean" use="optional" />
                                </xs:extension>
                              </xs:simpleContent>
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>

The above suffers from the following problems:
1.)  It allows the "default" attribute to be set to true for any number of
<computer>.
2.)  With the <xs:restriction> element, the parser complained that "Element
'extension' is invalid, misplaced, or occurs too often."

Would really appreciate any input as to the modifications required to
achieve my objectives.  Thanks.

Peter


-----------------------------------------------------------------
The xml-dev list is sponsored by XML.org <http://www.xml.org>, an initiative
of OASIS <http://www.oasis-open.org>

The list archives are at http://lists.xml.org/archives/xml-dev/

To subscribe or unsubscribe from this list use the subscription
manager: <http://www.oasis-open.org/mlmanage/index.php>

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.