W3C home > Mailing lists > Public > www-xml-schema-comments@w3.org > January to March 2001

Re: question on attributes

From: <Noah_Mendelsohn@lotus.com>
Date: Wed, 14 Feb 2001 00:15:45 -0500
To: "Fisseha, Haeran" <hfisseha@netfish.com>
Cc: "'www-xml-schema-comments@w3.org'" <www-xml-schema-comments@w3.org>
Message-ID: <OF551C1EB7.6FAB544D-ON852569F3.00096570@lotus.com>
Haeran Fissheha writes:

>> I wanted to ask if W3C Schema standards allow 
>> the use of sequential identical child elements
>> that are differentiated only by the value of an attribute

Your question isn't quite clear, but I think the answer is:  sure, schemas 
allows this.  The question really is, how specifically can you validate 
complex patterns.  I think you envision an instance fragment like:

        <date purpose="shippingDate">....</date>
        <date purpose="billingDate">.....</date>

Can you write schemas that will accept this instance? Absolutely (I'm 
doing the following without access to a validator, so there may be bugs):

  <element name="purchaseOrder:>
        <element name="date" maxOccurs="unbounded">
              ....whatever content you want for date defined here
            <attribute name="purpose">
                <restriction base="string">
                     <enumeration value="shippingDate"/>
                     <enumeration value="billingDate"/>
                   ...more here...

However, what you CANNOT do is say things like "only one shipping date and 
one billing date per order".  Those are co-occurrence constraints.  Known 
to be useful, but not provided in V1 of schemas. 

Of course, schemas will work better if you use more explicit markup in 
your basic data formats.  Any of the following are easier to validate, and 
probably to use for other XML purposes as well:


Or, if you like having an explicit tag for the date type:


or if you like the new schema constructs:
        <shippingdate  xsi:type="poDate">....</shippingdate>
        <billingdate xsi:type="poDate">....</billingdate>

With any of these constructs, you can force one per order, for example. 
Note that for the first suggested format, you might want to make an 
substitution group to cover the case where any data was permitted.  Hope 
this helps.

Noah Mendelsohn                                    Voice: 1-617-693-4036
Lotus Development Corp.                            Fax: 1-617-693-8676
One Rogers Street
Cambridge, MA 02142
Received on Wednesday, 14 February 2001 00:28:16 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:49:54 UTC