Re: Using multiple namespaces in an XML instance

Hi Lukas,

> XML Schemas version 2: Explicit references
> ========================================[stuff.xsd]
> <?xml version="1.0" encoding="UTF-8"?>
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>
>  <xsd:import namespace="http://www.stuff.com/fruit"
> schemaLocation="fruit.xsd"/>
>
>  <xsd:element name="stuff" type="stuff-type"/>
>
>  <xsd:complexType name="stuff-type">
>   <xsd:sequence>
>    <xsd:element name="count" type="xsd:nonNegativeInteger"/>
>    <xsd:element ref="fruit:apple" minOccurs="1" maxOccurs="1"/>
>    <xsd:element ref="fruit:orange" minOccurs="1" maxOccurs="1"/>
>    <xsd:element ref="fruit:other" minOccurs="1" maxOccurs="1"/>
>   </xsd:sequence>
>  </xsd:complexType>
>
> </xsd:schema>

I think that this might be the source of your problem. You haven't
included namespace declarations for the fruit namespace, so when the
schema validator sees ref="fruit:apple" and tries to work out what
'fruit' might mean, it hasn't a clue.

Try adding a namespace declaration that associates the prefix 'fruit'
with the namespace 'http://www.stuff.com/fruit':

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:fruit="http://www.stuff.com/fruit">
...
</xsd:schema>

Similarly, in:

> ========================================[fruit.xsd]
> <?xml version="1.0" encoding="UTF-8"?>
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>             xmlns:fruit="http://www.stuff.com/fruit"
>             targetNamespace="http://www.stuff.com/fruit"
>             elementFormDefault="qualified"
>             attributeFormDefault="unqualified">
>
>  <xsd:import namespace="http://www.stuff.com/vegies"
> schemaLocation="vegies.xsd"/>
>
>  <xsd:element name="apple" type="xsd:string"/>
>  <xsd:element name="orange" type="xsd:string"/>
>  <xsd:element name="other">
>   <xsd:complexType>
>    <xsd:sequence>
>     <xsd:element ref="vegies:carrots" minOccurs="1" maxOccurs="1"/>
>     <xsd:element ref="vegies:beans" minOccurs="1" maxOccurs="1"/>
>    </xsd:sequence>
>   </xsd:complexType>
>  </xsd:element>
>
> </xsd:schema>

You need to declare the vegies namespace so that you can refer to
elements in that namespace.

> I don't have access to C++, so Xerces-C++ is not really an option.

You can download the executable and run it from the command line, even
if you can't run it from code, just to test. That's all I'm doing.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Thursday, 20 December 2001 11:08:03 UTC