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

RE: XML Schema: At Least One of X Elements Must Appear


xsd at least one element
Title: RE: XML Schema: At Least One of X Elements Must Appear

Sure - here is an example XML document excerpt:

                <ReferenceIdentificationDetails>
                        <FinalSequenceNumber>XXXXXXXXXXX</FinalSequenceNumber>
                        <ShipmentNumber>XXXXXXXXX</ShipmentNumber>
                        <TransportationControlNumber>XXXXXXX</TransportationControlNumber>
                        <ShipmentDate>2002-02-02</ShipmentDate>
                </ReferenceIdentificationDetails>

This is the equivalent of the REF01/02 scenario I describe below, where:

REF01   VALUE           EQUATES TO ELEMENT     
----------------                -----------------------------
FS                              FinalSequenceNumber
SI                              ShipmentNumber 
TG                              TransportationControlNumber

(the ShipmentDate is REF03, and is optional)

In the schema, I've represented this as the following complex type:

        <xsd:complexType name = "ReferenceIdentificationDetailsType">
                <xsd:sequence>
                        <xsd:element ref = "FinalSequenceNumber" minOccurs="0"/>
                        <xsd:element ref = "ShipmentNumber" minOccurs="0"/>
                        <xsd:element ref = "TransportationControlNumber" minOccurs="0"/>
                        <xsd:element ref = "ShipmentDate" minOccurs="0"/>
                </xsd:sequence>
        </xsd:complexType>

As you can see, I had to make all 3 "qualified" elements optional, because it is not predictable which of the 3 will appear.

Thanks,
Joe Chiusano
LMI

> **************************************************************************
>   Joseph M. Chiusano
>   Logistics Management Institute
>   2000 Corporate Ridge
>   McLean, VA 22102
>   Email: jchiusano@l...
>   Tel: 571.633.7722
> **************************************************************************
>


-----Original Message-----
From: Dare Obasanjo [mailto:dareo@m...]
Sent: Sunday, August 18, 2002 1:41 PM
To: CHIUSANO, Joseph; Ken Sall; CHIUSANO, Joseph; xml-dev@l...
Subject: RE: XML Schema: At Least One of X Elements Must
Appear


In general I don't think W3C XML Schema can satisfy your requirements but believe that there may be a work around for specific cases. Your example wasn't detailed enough to tell if your case is one where a work around is possible. Perhaps some sample XML or schema fragment?

        -----Original Message-----
        From: CHIUSANO, Joseph [mailto:JCHIUSANO@l...]
        Sent: Sun 8/18/2002 10:35 AM
        To: 'Ken Sall'; CHIUSANO, Joseph; xml-dev@l...
        Cc:
        Subject: RE: XML Schema: At Least One of X Elements Must Appear
       
       

        Not sure how use of a wildcard can help here....would you be willing to provide more specifics?

        > **************************************************************************
        >   Joseph M. Chiusano
        >   Logistics Management Institute
        >   2000 Corporate Ridge
        >   McLean, VA 22102
        >   Email: jchiusano@l...
        >   Tel: 571.633.7722
        > **************************************************************************
        >


        -----Original Message-----
        From: Ken Sall [mailto:ken@s...]
        Sent: Sunday, August 18, 2002 1:33 PM
        To: CHIUSANO, Joseph; xml-dev@l...
        Subject: Re: XML Schema: At Least One of X Elements Must
        Appear


        XML Schema: At Least One of X Elements Must AppearJoseph wrote> I am 99.9%
        sure that there is no way to represent in XML Schema that "at least one of
        the following X elements must appear in the XML document" - **am I
        correct?**

        How about:

                 <xsd:any  minOccurs="0" maxOccurs="unbounded" > <!-- or 1 -->
                  <!-- nest xsd:sequence or xsd:choice here -->
                </xsd:any>

        - Ken Sall               kensall@c... or ken@s...
        - XML Consultant/Author  http://mywebpages.comcast.net/kensall/
        - XML Family of Specifications: A Practical Guide (just published)
        - http://WDVL.Internet.com/Authoring/Languages/XML/XMLFamily/



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.