XOM chokes on fixed optional attribute

Description

(Imported from Google Code)
Sent to XOM interest mailing list:

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-schemaLocation points 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

Environment

None

Assignee

Brian Uri

Reporter

Brian Uri

Labels

None

Fix versions

Priority

Medium
Configure