W3C home > Mailing lists > Public > xmlschema-dev@w3.org > December 2001

Re: Using multiple namespaces in an XML instance

From: Lukas Tan <lukas.tan@cmis.csiro.au>
Date: Wed, 19 Dec 2001 17:19:14 -0500 (EST)
Message-ID: <000801c188db$006cf300$c8595398@VOYAGERBT>
To: <xmlschema-dev@w3.org>, <jeni@jenitennison.com>
Hello and thanks for the reply.

I had eventually worked out a way, which involved binding namespaces to
schemas in the XML instances:

> <stuff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xsi:noNamespaceSchemaLocation="stuff.xsd"
>        xsi:schemaLocation="http://www.stuff.com/fruit
>                            fruit.xsd
>                            http://www.stuff.com/vegies
>                            vegies.xsd
>                            http://www.stuff.com/cereals
>                            cerials.xsd"
>        xmlns:fruit="http://www.stuff.com/fruit"
>        xmlns:vegies="http://www.stuff.com/vegies"
>        xmlns:cereals="http://www.stuff.com/cereals">
> ...
> </stuff>

and using the "xsd:any" wildcard in the "stuff" schema:

>   <xs:sequence>
>     <xs:element name="count" type="xsd:nonNegativeInteger" />
>     <xs:any namespace="http://www.stuff.com/fruit
>                        http://www.stuff.com/vegies
>                        http://www.stuff.com/cereals"
>             minOccurs="6" />
>   </xs:sequence>

While this is not the ideal solution, as I do want to control exactly which
elements from the other namespaces occur inside the "stuff" element (by some
means such as using the "ref" attribute of the "xsd:element" element), it
was the only way I could get the validator (Xerces) to accept the schemas.
If I try the other (more desirable) approach:

> <xsd:complexType name="stuff-type">
>   <xsd:all>
>     <xsd:element name="count" type="xsd:nonNegativeInteger" />
>     <xsd:element ref="fruit:apple" />
>     <xsd:element ref="fruit:orange" />
>     <xsd:element ref="vegies:carrot" />
>     <xsd:element ref="vegies:beans" />
>     <xsd:element ref="cereals:rice" />
>     <xsd:element ref="cereals:bread" />
>   </xsd:all>
> </xsd:complexType>

with:

> <xsd:import namespace="http://www.stuff.com/fruit"
>            schemaLocation="fruit.xsd" />
> .....

Xerces says it "Cannot resolve the name 'fruit:apple' to a(n) elment
declaration component." (typo and all).

As an aside, even when using the "any" wildcard as I currently am, if I
don't define the types of elements inside the element declaration (ie I try
to define the element type by saying <xsd:element name="blah"
type="blah-type">, and then defining "blah type" separately), Xerces
produces the same error. Do types need to be namespace prefixed?

So, is there anything else I'm missing, or is it time for the workman to
blame his tools and get another validator?

Just a thought, what's the difference between "xsd" and "xs". The initial
reccommendation (thanks again)was to use "xs:import", which I converted to
"xsd:import" because I didn't know the namespace for "xs". Is this the cause
of all my troubles?

Update: When changed to "xs:import", Xerces reports "s4s-elt-schema-ns: The
namespace of element 'import' must be from the schema namespace." The
"cannot resolve" errors remain.

Thanks

Lukas
Received on Thursday, 20 December 2001 10:25:38 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:25 GMT