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:element name="Address" type="US"/>
    <xsd:element name="Address" type="China"/>
 <xsd:complexType name="US">
   <xsd:element name="Street" type="xsd:string"/>
   <xsd:element name="City" type="xsd:string"/>
   <xsd:element name="Zip" type="xsd:string"/>
 <xsd:complexType name="China">
   <xsd:element name="Street" type="xsd:string"/>
   <xsd:element name="City" type="xsd:string"/>
   <xsd:element name="Province" type="xsd:string"/>

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>
 <Address xsi:type="China">
  <Street>12344 lo pai street</Street>

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 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:52 UTC