Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Possible Bug: XOM Builder chokes on fixed optional attribute

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: "Brian Uri!" <brian AT urizone.net>
  • To: XOM API for Processing XML with Java <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] Possible Bug: XOM Builder chokes on fixed optional attribute
  • Date: Mon, 26 Sep 2011 10:08:51 -0400

Thanks for your reply, Michael!

I've found that XOM has this same behavior for any fixed optional
attributes, not just those referenced from another schema.

The workaround I am employing for now is to remove the fixed="resource" from
the attribute definition, and then adding a validation step in Java that
confirms the attribute is set to "resource" after XOM has loaded the
instance. This is sufficient for my single fringe case, but probably not
scalable.

Regards,
BU

On Sun, Sep 25, 2011 at 3:21 PM, Michael Kay <mike AT saxonica.com> wrote:

> The XSD 1.0 rules for fixed/default attributes of type QName are very
> poorly defined, and it's best to avoid using them.
>
> You code should work OK with an XSD 1.1 processor (I think), where the
> rules have been more clearly spelled out.
>
> Michael Kay
> Saxonica
>
> On 24/09/2011 22:07, Brian Uri! wrote:
> > Hello,
> >
> > I seem to be hitting a bug, but I can't determine whether it's a bug in
> XOM
> > or just schemas which could be better written. I've pruned down the code
> and
> > schemas to the bare bits needed to reproduce the issue below.
> >
> > I have a schema which defines an element and has a fixed optional
> attribute
> > from a third-party schema (XLink 1.1):
> >
> > <?xml version="1.0" encoding="utf-8"?>
> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
> > xmlns="urn:buri:bugtest" xmlns:buri="urn:buri:bugtest"
> > xmlns:xlink="http://www.w3.org/1999/xlink";
> > targetNamespace="urn:buri:bugtest"
> elementFormDefault="qualified"
> > attributeFormDefault="qualified">
> >
> > <xs:import namespace="http://www.w3.org/1999/xlink";
> > schemaLocation="XLink.xsd"/>
> >
> > <xs:element name="revision" type="RevisionType" />
> > <xs:complexType name="RevisionType">
> > <xs:simpleContent>
> > <xs:extension base="xs:string">
> > <xs:attribute ref="xlink:type" fixed="resource"
> > use="optional"/>
> > </xs:extension>
> > </xs:simpleContent>
> > </xs:complexType>
> > </xs:schema>
> >
> > The XLink 1.1 schema provides the definition for the xlink:type
> attribute:
> >
> > <?xml version='1.0' encoding='UTF-8'?>
> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
> > xmlns:xlink="http://www.w3.org/1999/xlink";
> > targetNamespace="http://www.w3.org/1999/xlink";>
> >
> > <xs:attribute name="type" type="xlink:typeType" />
> > <xs:simpleType name="typeType">
> > <xs:restriction base="xs:token">
> > <xs:enumeration value="simple"/>
> > <xs:enumeration value="extended"/>
> > <xs:enumeration value="title"/>
> > <xs:enumeration value="resource"/>
> > <xs:enumeration value="locator"/>
> > <xs:enumeration value="arc"/>
> > </xs:restriction>
> > </xs:simpleType>
> > </xs:schema>
> >
> > When I try to build a Document with the instance below in a file,
> everything
> > works fine:
> >
> > <?xml version='1.0' encoding='UTF-8'?>
> > <buri:revision xmlns:xlink="http://www.w3.org/1999/xlink";
> > xmlns:buri="urn:buri:bugtest" xlink:type="resource" />
> >
> > However, if I remove the attribute from the instance, like this:
> >
> > <?xml version='1.0' encoding='UTF-8'?>
> > <buri:revision xmlns:xlink="http://www.w3.org/1999/xlink";
> > xmlns:buri="urn:buri:bugtest" />
> >
> > I get this error from XOM:
> >
> > nu.xom.ParsingException: Unprefixed attribute type cannot be in
> default
> > namespace http://www.w3.org/1999/xlink
> > at nu.xom.Builder.build(Unknown Source)
> > [...]
> > Caused by: nu.xom.NamespaceConflictException: Unprefixed attribute
> type
> > cannot be in default namespace http://www.w3.org/1999/xlink
> > at nu.xom.Attribute._setNamespace(Unknown Source)
> > at nu.xom.Attribute.<init>(Unknown Source)
> > at nu.xom.NodeFactory.makeAttribute(Unknown Source)
> >
> > If I understand it correctly, a fixed optional attribute need not exist
> in
> > an instance, but must have the fixed value if it does, so an instance
> > without it should still be valid. Since the 2nd instance doesn't even
> > mention "type", I'm not sure why XOM would be trying to build a type
> > attribute at all.
> >
> > The environment details:
> > xom 1.2.6
> > xercesImpl 2.9.1
> > xml-apis 1.3.04
> >
> > XMLReader: org.apache.xerces.parsers.SAXParser
> > http://xml.org/sax/features/validation=true
> > http://apache.org/xml/features/validation/schema=true
> >
> http://apache.org/xml/properties/schema/external-schemaLocationpoints
> > at the schema file
> >
> > Test Code:
> > Builder builder = new Builder(xmlReader, true);
> > builder.build(new FileReader(new File(theInstance)));
> >
> > Any insights would be appreciated. I'll be glad to provide more details
> if I
> > pruned too much!
> >
> > Thanks!
> > BU
>




Archive powered by MHonArc 2.6.24.

Top of Page