W3C home > Mailing lists > Public > xmlschema-dev@w3.org > August 2001

Re: elements with the same name

From: D Gross <justdave@onebox.com>
Date: Wed, 22 Aug 2001 11:44:58 -0400 (EDT)
To: xmlschema-dev@w3.org
Message-Id: <20010822154416.LQUP12461.mta11.onebox.com@onebox.com>
> There is one tag name <Address>, but based on its
> attribute value of "type", the elements inside of
> <Address> varies.  

I would do it like so:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" elementFormDefault="qualified">
 <xsd:element name="top">
  <xsd:complexType>
   <xsd:sequence>
    <xsd:element name="Address" type="US"/>
    <xsd:element name="Address" type="China"/>
   </xsd:sequence>
  </xsd:complexType>
 </xsd:element>
 <xsd:complexType name="US">
  <xsd:sequence>
   <xsd:element name="Street" type="xsd:string"/>
   <xsd:element name="City" type="xsd:string"/>
   <xsd:element name="Zip" type="xsd:string"/>
  </xsd:sequence>
 </xsd:complexType>
 <xsd:complexType name="China">
  <xsd:sequence>
   <xsd:element name="Street" type="xsd:string"/>
   <xsd:element name="City" type="xsd:string"/>
   <xsd:element name="Province" type="xsd:string"/>
  </xsd:sequence>
 </xsd:complexType>
</xsd:schema>

Then your XML would look like this:
<top xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance">
 <Address xsi:type="US">
  <Street>12345 main street</Street>
  <City>JoeTown</City>
  <Zip>2456</Zip>
 </Address>
 <Address xsi:type="China">
  <Street>12344 lo pai street</Street>
  <City>...</City>
  <Province>..</Province>
 </Address>
</top>

Note the xsi:type and the declaration of the Schema Instance namespace.

-- Dave
D Gross
justdave@onebox.com - email
(312) 777-4000 x7673 - voicemail/fax



__________________________________________________
FREE voicemail, email, and fax...all in one place.
Sign Up Now! http://www.onebox.com
Received on Wednesday, 22 August 2001 11:48:35 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:23 GMT