Re: Same element name, different namespaces: is that possible?

It is straightforward to do what you want, but it requires at least
two schema documents, as W3C XML Schema restricts each schema document
to a single namespace.  I recommend that you read the XML Schema
Primer, particular chapter 5 [1].

Your particular problem is solved as follows:

v.xsd:
<xs:schema targetNamespace="http://www.example.org/ns-v">
 <xs:element name="price" type="xs:decimal"/>
</xs:schema>

g.xsd:
<xs:schema targetNamespace="http://www.example.org/ns-g">
 <xs:element name="price" type="xs:float"/>
</xs:schema>

master.xsd:
<xs:schema targetNamespace="http://www.example.org/ns-top" xmlns:v="http://www.example.org/ns-v" xmlns:g="http://www.example.org/ns-g">
 <xs:import namespace="http://www.example.org/ns-v" schemaLocation="v.xsd"/>
 <xs:import namespace="http://www.example.org/ns-g" schemaLocation="g.xsd"/>
 
 <xs:element name="shop">
  <xs:complexType>
   <xs:sequence>
    <xs:element ref="v:price"/>
    <xs:element ref="g:price"/>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>

I've used _three_ documents and three namespaces, because your example
didn't make it clear whether 'shop' was in the same namespace as
either of your 'price' elements -- you could combine master.xsd with
e.g. g.xsd if 'shop' is actually in that namespace, in which case only
the import for the 'ns-v' namespace would be required.

Hope this helps,

ht

[1] http://www.w3.org/TR/xmlschema-0/#quartelyReport
-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
                      Half-time member of W3C Team
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
	    Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
		     URL: http://www.ltg.ed.ac.uk/~ht/
 [mail really from me _always_ has this .sig -- mail without it is forged spam]

Received on Monday, 27 October 2003 05:24:32 UTC