- From: Andrew Welch <andrew.j.welch@gmail.com>
- Date: Mon, 23 Apr 2007 16:05:47 +0100
- To: "noah_mendelsohn@us.ibm.com" <noah_mendelsohn@us.ibm.com>
- Cc: xmlschema-dev@w3.org
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
Received on Monday, 23 April 2007 15:05:54 UTC