OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ XSD ] xml instance with more than one namespace

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,

<xs:schema targetNamespace="www.test.org/a" xmlns:xs="http://www.w3.org/2001/XMLSchema"
  <xs:element name="From_a" type="xs:string"/>

<xs:schema targetNamespace="www.test.org/b" xmlns:xs="http://www.w3.org/2001/XMLSchema"
  <xs:element name="From_b" type="xs:string"/>

<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:element ref="a:From_a"/>
         <xs:element ref="b:From_b"/>

<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>