Re: [xml] Question about default namespace with XML Schema
- From: Kasimier Buchcik <kbuchcik 4commerce de>
- To: GUY Fabrice <fabrice guy gmail com>
- Cc: "xml gnome org" <xml gnome org>
- Subject: Re: [xml] Question about default namespace with XML Schema
- Date: Mon, 02 May 2005 12:57:58 +0200
Hi,
On Mon, 2005-05-02 at 11:03 +0200, GUY Fabrice wrote:
Hi,
I'm using this schema :
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="ELEMENTS">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="element" type="xsd:string" minOccurs="0"
maxOccurs="unbounded"/>
<xsd:element name="element2" type="xsd:string" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:key name="key">
<xsd:selector xpath="element"/>
<xsd:field xpath="."/>
</xsd:key>
<xsd:keyref name="keref" refer="key">
<xsd:selector xpath="element2"/>
<xsd:field xpath="."/>
</xsd:keyref>
</xsd:element>
</xsd:schema>
with this xml file :
<?xml version="1.0" encoding="ISO-8859-1"?>
<ELEMENTS>
<element>test1</element>
<element>test2</element>
<element2>test2</element2>
</ELEMENTS>
And that works perferctly fine.
But when I try to use the default namespace in the schema (to avoid
using the xsd: prefix), I get this message when I validate it with
xmllint :
test.xsd:14: element keyref: Schemas parser error : keyRef 'keref':
References from this schema to components in the namespace
'http://www.w3.org/2001/XMLSchema' are not valid, since not indicated
by an import statement.
The error report is OK. The "refer" and the "ref" attributes hold
QNames, acting as references to schema components. So the value "key"
expands to the QName "{http://www.w3.org/2001/XMLSchema}key", for which
there is no schema component; furthermore, references to "foreign"
namespaces (i.e namespaces other than specified in targetNamespace)
are disallowed if not explicitely <import>ed by the schema.
Here's my schema with the default namespace :
<?xml version="1.0" encoding="ISO-8859-1"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<element name="ELEMENTS">
<complexType>
<sequence>
<element name="element" type="string" minOccurs="0"
maxOccurs="unbounded"/>
<element name="element2" type="string" minOccurs="0"
maxOccurs="unbounded"/>
</sequence>
</complexType>
<key name="key">
<selector xpath="element"/>
<field xpath="."/>
</key>
<keyref name="keref" refer="key">
<selector xpath="element2"/>
<field xpath="."/>
</keyref>
</element>
</schema>
Have I missed something (namespace declaration,...) or this is a bug ?
If you want the schema to have no targetNamespace, you need to use a
prefix for the XSD nodes, or avoid references to components; the latter
being quite unpractical.
Regards,
Kasimier
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]