Problem with ref-attributes and schema validation 2007-06-14 - By Asgeir Frimannsson
Hi all,
I have come across something that _might_ be a bug in xerces. Let me explain by example:
Given the following schema:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xml="http://www.w3.org/XML/1998/namespace" 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 ref="xml:space" default="preserve"/> <xsd:attribute name="name" type="xsd:string" use="required"/> </xsd:complexType> </xsd:element> </xsd:schema>
Notice the xml:space attribute has a default value 'preserve'. Now, given the following instance:
<?xml version="1.0" encoding="utf-8"?> <animal xmlns="http://www.example.com" xmlns:x="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>
Note that no value is set for xml:space, so I expect xerces to insert this for me when doing schema validation. To make the possible bug simple to reproduce, I'll use one of the xerces samples for validating and writing this document. Using the following options: Namespace processing: on Namespace prefixes: on Validation: on Schema validation support: on Schema full checking: on
java sax.Writer -n -np -s -f -v instance.xml
...which produces the following output:
<animal name="dog" space="preserve" xmlns="http://www.example.com" xmlns:x="http://www.example.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com SpaceBug.xsd"> hi, i'm a dog </animal>
Notice how the xml:space attribute is now unqualified. This is reproducable for any namespace, not just the special xml namespace.
I initially bumped into this problem when using the XOM library (reported [1]), and it seems that the namespace uri is correctly set when inserting the default value, but the prefix is lost.
cheers, asgeir
[1] http://lists.ibiblio.org/pipermail/xom-interest/2007-June/003484.html
-- 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@(protected)
--------------------------------------------------------------------- To unsubscribe, e-mail: j-dev-unsubscribe@(protected) For additional commands, e-mail: j-dev-help@(protected)
|
|