[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ XSD ] xml instance with more than one namespace
- From: Eddie Robertsson <eddie@allette.com.au>
- To: xmldev@visto.com
- Date: Fri, 06 Apr 2001 17:38:56 +1000
Gavin Bong wrote:
> If my xml instance document has more than one namespace in it, can I add multiple namespace URIs to my
> targetNameSpace attribute in the schema document ?
No, you can only have one targetNamespace for each schema. What you have to do is to define one schema for
each namespace you want to use in your instance. In one of the schemas you then use the import function to
import the other namespace declarations. For example,
Schema1:
<xs:schema targetNamespace="www.test.org/a" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="www.test.org/a">
<xs:element name="From_a" type="xs:string"/>
</xs:schema>
Schema2:
<xs:schema targetNamespace="www.test.org/b" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="www.test.org/b">
<xs:element name="From_b" type="xs:string"/>
</xs:schema>
Schema3:
<xs:schema targetNamespace="www.test.org/c" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="www.test.org/c" xmlns:a="www.test.org/a" xmlns:b="www.test.org/b">
<xs:import namespace="www.test.org/a" schemaLocation="Schema1.xsd">
<xs:import namespace="www.test.org/b" schemaLocation="Schema2.xsd">
<xs:element name="From_c">
<xs:complexType>
<xs:sequence>
<xs:element ref="a:From_a"/>
<xs:element ref="b:From_b"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Instance:
<c:From_c xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
www.test.org/a Schema1.xsd
www.test.org/b Schema2.xsd
www.test.org/c www.test.org/c"
xmlns:a="www.test.org/a" xmlns:b="www.test.org/b" xmlns:c="www.test.org/c">
<a:From_a>I'm from www.test.org/a...</a:From_a>
<b:From_b>I'm from www.test.org/b...</b:From_b>
</c:From_c>
Cheers,
/Eddie