Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Inconsistent xml:id sanity checks

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <wolfgang.hoschek AT mac.com>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] Inconsistent xml:id sanity checks
  • Date: Sun, 12 Mar 2006 16:20:14 -0800

There's an inconsistency between the xml:id sanity checks used by 1) new Attribute(...) and 2) Attribute.build(...).
This is apparent when trying to parse the test files XOM/data/xmlid/ tests/001_normalize.xml and XOM/data/xmlid/tests/011_ok from the XOM testsuite via a non-validating XOM Builder. These files parse fine when using the (trusted) path 1:

new Builder().build(...)

but are rejected with the (untrusted) path 2:

new Builder(new NodeFactory() {}).build(...)

Exception in thread "main" nu.xom.ParsingException: NCNames cannot start with the character 20
at nu.xom.Builder.build(Builder.java:1157)
at nu.xom.Builder.build(Builder.java:625)
at nu.xom.Builder.build(Builder.java:1001)
at nux.xom.sandbox.StaxBuilderTest.run(StaxBuilderTest.java:93)
at nux.xom.sandbox.StaxBuilderTest.main(StaxBuilderTest.java: 79)
Caused by: nu.xom.IllegalNameException: NCNames cannot start with the character 20
at nu.xom.Verifier.throwIllegalNameException(Verifier.java:158)
at nu.xom.Verifier.checkNCName(Verifier.java:137)
at nu.xom.Attribute._setValue(Attribute.java:353)
at nu.xom.Attribute.<init>(Attribute.java:170)
at nu.xom.NodeFactory.makeAttribute(NodeFactory.java:254)
at nu.xom.XOMHandler.startElement(XOMHandler.java:177)
at org.apache.xerces.parsers.AbstractSAXParser.startElement (Unknown Source)
at org.apache.xerces.impl.XMLNamespaceBinder.handleStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNamespaceBinder.startElement (Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement (Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl $FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument (Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at nu.xom.Builder.build(Builder.java:1138)

Xerces considers xml:id values such as xml:id=" and xml:id=" te st " wellformed/valid (tested with xerces-2.6.2, 2.7.1 and 2.8.0), whereas the public XOM Attribute constructor doesn't.

Depending on philosophy, the fix is to a) not check values of xml:id attributes for name wellformedness, or to b) add a Verifier.checkNCName(value) check in Attribute.build(...) when xml:id is detected (line 213 in Attribute.java). Either way, the current state is inconsistent, hence confusing.

Wolfgang.




Archive powered by MHonArc 2.6.24.

Top of Page