[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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

  • From: Eddie Robertsson <eddie@a...>
  • To: xmldev@v...
  • Date: Fri, 06 Apr 2001 17:38:56 +1000

xs import 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,

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



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.