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

Re: Problems with Simple XML Validation

From: Eddie Robertsson <eddie@allette.com.au>
Date: Wed, 05 Dec 2001 11:48:10 +1100
Message-ID: <3C0D6ECA.AF241EBC@allette.com.au>
To: JKim@orbitz.com
CC: xmlschema-dev@w3.org, Rahul.Srivastava@Sun.COM, Ravin.Shah@morganstanley.com, ychiu@orbitz.com, wshort@orbitz.com
> I have added a default namespace so that my xsd file now looks like this:
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="AnotherTestSpace"
> xmlns="AnotherTestSpace"
> elementFormDefault="qualified"
> >
>
> <xsd:element name="shipOrder" type="order"/>
> <xsd:complexType name="shipAddress">
> <xsd:sequence>
> <xsd:element   name="name"      type="xsd:string"/>
> <xsd:element   name="street"    type="xsd:string"/>
> <xsd:element   name="address"   type="xsd:string"/>
> <xsd:element   name="country"   type="xsd:string"/>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:complexType name="cdItem">
> <xsd:sequence>
> <xsd:element   name="title"     type="xsd:string"/>
> <xsd:element   name="quantity"  type="xsd:positiveInteger"/>
> <xsd:element   name="price"     type="xsd:decimal"/>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:complexType name="cdItems">
> <xsd:sequence>
> <xsd:element   name="item"      type="cdItem"/>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:complexType name="order">
> <xsd:sequence>
> <xsd:element   name="shipTo"    type="shipAddress"/>
> <xsd:element   name="items"     type="cdItems"/>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:schema>

Looks good!

> Here are my two attempts at modifying my xml file:
>
> Attempt 1:
> <?xml version="1.0" encoding="UTF-8"?>
> <foo:shipOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="AnotherTestSpace order_schema.xsd"
> xmlns:foo="AnotherTestSpace"
> >
> <shipTo>
> <name>Tove Svendson</name>
> <street>Ragnhildvei 2</street>
> <address>4000 Stavanger</address>
> etc...

No, this won't work. Since you have elementFormDefault="qualified" in your schema all
elements in the instance document will have to be qualified with a namespace. In the
above its only the shipOrder element that is qualified and the rest of the elements
are unqualified.

> Attempt 2:
> <?xml version="1.0" encoding="UTF-8"?>
> <shipOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="AnotherTestSpace order_schema.xsd"
> xmlns="AnotherTestSpace"
> >
> <shipTo>
> <name>Tove Svendson</name>
> <street>Ragnhildvei 2</street>
> <address>4000 Stavanger</address>
> etc...

This should work though. It works fine in all the validators I've tested with (XML
Spy, XSV and Xerces 2 beta).

> In each case I get the following error:
>
> [Error] simple.xml:5:2: General Schema Error: Grammar with uri 2:
> AnotherTestSpace , can not found.
>
> In addition I still get the other errors from before:
>
> [Error] simple.xml:5:2: Element type "shipOrder" must be declared.
> [Error] simple.xml:6:9: Element type "shipTo" must be declared.
> etc...
>
> I am using Xerces 1.3.0's SAXCount parser.
> I verified that the xsd file is in fact named order_schema.xsd,
> and that it exists in the same directory as my xml file.  I must be missing
> something fundamental which I don't know about.

I'd say it's a bug in Xerces 1.3.0.

Cheers,
/Eddie
Received on Tuesday, 4 December 2001 19:40:21 GMT

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