Altova Mailing List Archives>Archive Index >xmlschema-dev Archive Home >Recent entries >Thread Prev - Re: multiple namespaces >Thread Next - RE: multiple namespaces Re: multiple namespacesTo: "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 | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
