Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Possible bug with Schema validation and the xml prefix

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: "Asgeir Frimannsson" <asgeirf AT gmail.com>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] Possible bug with Schema validation and the xml prefix
  • Date: Wed, 13 Jun 2007 14:39:41 +1000

Hi,

I started using XOM last weekend, and have bumped into something that
might be a bug. It relates to parsing documents that uses XML schema
validation. It's easier explained by example:

Using XOM 1.2b2 and Xerces 2.9.0.

Given the following XML schema:

<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified"
targetNamespace="http://www.example.com";>

<!-- Import for xml:space -->
<xsd:import namespace="http://www.w3.org/XML/1998/namespace";
schemaLocation="http://www.w3.org/2001/xml.xsd"/>

<xsd:element name="animal">
<xsd:complexType mixed="true">
<xsd:attribute default="default" ref="xml:space" use="optional"/>
<xsd:attribute name="name" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>

</xsd:schema>

Notice how the schema defines an attribute referring to xml:space
(allowed values are 'preserve' and 'default'), and also notice that
the default value for this attribute is set to 'default'.

Now, given the following instance:

<?xml version="1.0" encoding="utf-8"?>
<animal xmlns="http://www.example.com";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://www.example.com SpaceBug.xsd"
name="dog">
hi, i'm a dog
</animal>

Notice that the <animal> element does not define a 'xml:space' attribute.

Now, let's do some simple XOM magic involving schema validation:

XMLReader xerces = XMLReaderFactory
.createXMLReader("org.apache.xerces.parsers.SAXParser");
xerces.setFeature(
"http://apache.org/xml/features/validation/schema";, true);

File testFile = new File("instance.xml");
Builder parser = new Builder(xerces, true);
Document doc = parser.build(testFile);
System.out.println(doc.toXML());

This will throw an exception (nu.xom.ParsingException: Wrong prefix
for the XML namespace: ).

The issue seems to relate to the fact that the <animal> element does
not include a 'xml:space' attribute. Since the attribute has a default
value in the schema, Xerces will create the default value and pass it
on to XOM. This default value has the XML namespace, but no prefix
'xml', which causes XOM to complain.

cheers,
asgeir

--
Asgeir Frimannsson
PhD Candidate
School of Software Engineering and Data Communications
Queensland University of Technology
126 Margaret Street, Level 3
Brisbane QLD 4001, Australia

Phone: (+61) 7 3138 9332 Mob: (+61) 405 412 696
Email: asgeirf AT gmail.com




Archive powered by MHonArc 2.6.24.

Top of Page