You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Asgeir Frimannsson <as...@gmail.com> on 2007/06/14 13:39:47 UTC
Problem with ref-attributes and schema validation
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@gmail.com
---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org
Re: Problem with ref-attributes and schema validation
Posted by Asgeir Frimannsson <as...@gmail.com>.
Hi Michael,
Thanks for this clarification.
cheers,
asgeir
On 6/18/07, Michael Glavassevich <mr...@ca.ibm.com> wrote:
> Hi Asgeir,
>
> What you're observing is normal. The prefixes used in schema documents
> don't get carried over into the schema component model [1] or defaulted
> attributes [2] (just the local name and namespace URI). Note that
> sax.Writer is just a sample for users to learn how to use SAX. It doesn't
> do everything a real namespace-aware serializer should do like namespace
> fixup: selecting suitable prefixes for elements/attributes and adding the
> necessary namespace declarations to the document to make it well-formed.
>
> Thanks.
>
> [1] http://www.w3.org/TR/xmlschema-1/#Attribute_Declaration_details
> [2] http://www.w3.org/TR/xmlschema-1/#d0e8328
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> "Asgeir Frimannsson" <as...@gmail.com> wrote on 06/14/2007 07:39:47 AM:
>
> > 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@gmail.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
> > For additional commands, e-mail: j-dev-help@xerces.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-dev-help@xerces.apache.org
>
>
--
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@gmail.com
---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org
Re: Problem with ref-attributes and schema validation
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Asgeir,
What you're observing is normal. The prefixes used in schema documents
don't get carried over into the schema component model [1] or defaulted
attributes [2] (just the local name and namespace URI). Note that
sax.Writer is just a sample for users to learn how to use SAX. It doesn't
do everything a real namespace-aware serializer should do like namespace
fixup: selecting suitable prefixes for elements/attributes and adding the
necessary namespace declarations to the document to make it well-formed.
Thanks.
[1] http://www.w3.org/TR/xmlschema-1/#Attribute_Declaration_details
[2] http://www.w3.org/TR/xmlschema-1/#d0e8328
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
"Asgeir Frimannsson" <as...@gmail.com> wrote on 06/14/2007 07:39:47 AM:
> 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@gmail.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-dev-help@xerces.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org