Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: multiple namespaces

From: "Andrew Welch" <andrew.j.welch@-----.--->
To: "noah_mendelsohn@--.---.---" <----_----------@--.---.--->
Date: 4/23/2007 5:06:00 PM
Ok here's a complete example:

<ns1:root xmlns:ns1="firstNamespace" xmlns:ns2="secondNamespace">
	<ns1:foo>some text</ns1:foo>
	<ns2:bar>some <ns1:foo> more </ns1:foo> text</ns2:bar>
</ns1:root>

The keys points here are:

- there are two namespaces
- each namespace contains elements in the other namespace

In order to model this I created two schema documents ns1.xsd and
ns2.xsd which import each other:

==== ns1.xsd ====

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified"
    targetNamespace="firstNamespace"
	xmlns:ns1="firstNamespace"
	xmlns:ns2="secondNamespace">
	
	<xs:import namespace="secondNamespace" schemaLocation="ns2.xsd"/>
	
	<xs:element name="root" type="ns1:root"/>
	<xs:element name="foo" type="ns1:non-empty-string"/>
	
	<xs:complexType name="root">
		<xs:sequence>
			<xs:element ref="ns1:foo"/>
			<xs:element ref="ns2:bar"/>
		</xs:sequence>
	</xs:complexType>
	
	<xs:simpleType name="non-empty-string">		
		<xs:restriction base="xs:string">		
			<xs:minLength value="1"/>		
		</xs:restriction>		
    </xs:simpleType>	
</xs:schema>


==== ns2.xsd ====

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified"
    targetNamespace="secondNamespace"
	xmlns:ns1="firstNamespace"
	xmlns:ns2="secondNamespace">
	
	<xs:import namespace="firstNamespace" schemaLocation="ns1.xsd"/>
	
	<xs:element name="bar" type="ns2:bar"/>
	
	<xs:group name="various-elements">
		<xs:choice>
			<xs:element ref="ns1:foo" minOccurs="0"/>
			<!-- lots of other elements that can occur in any order -->
		</xs:choice>
	</xs:group>
	
	<xs:complexType name="bar" mixed="true">
		<xs:group ref="ns2:various-elements"/>
	</xs:complexType>
	
</xs:schema>


I'd like any comments on this approach - its seems strange to have
circular imports, and when referencing the simpleType and the group
prefixes are needed - unless as Mike says I add a default namespace,
which I think would make the top of the schema document:

targetNamespace="firstNamespace"
xmlns:ns1="firstNamespace"
xmlns="firstNamespace"

...which is fine but a little non-intuitive at the moment - is there a
preferred approach?

thanks
andrew

From mike@s... Mon Apr 23 15:40:56 2007
Received: from lisa.w3.org ([128.30.52.41])
	by frink.w3.org with esmtp (Exim 


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent