- 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>
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:
<purchaseOrder>
<date purpose="shippingDate">....</date>
<date purpose="billingDate">.....</date>
</purchaseOrder>
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:>
<complexType>
<sequence>
<element name="date" maxOccurs="unbounded">
<complexType>
....whatever content you want for date defined here
<attribute name="purpose">
<simpleType>
<restriction base="string">
<enumeration value="shippingDate"/>
<enumeration value="billingDate"/>
...more here...
</restriction>
</simpleType>
</attribute>
</complexType>
</element>
<sequence>
</complexType>
</element>
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:
<purchaseOrder>
<shippingdate>....</shippingdate>
<billingdate>....</billingdate>
</purchaseOrder>
Or, if you like having an explicit tag for the date type:
<purchaseOrder>
<shippingdate>
<date>....
</date>
</shippingdate>
<billingdate>
<date>....
</date>
</billingdate>
</purchaseOrder>
or if you like the new schema constructs:
<purchaseOrder>
<shippingdate xsi:type="poDate">....</shippingdate>
<billingdate xsi:type="poDate">....</billingdate>
</purchaseOrder>
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