[jdom-interest] JDOM 1.1.2 / Saxon 9.4.0.1: namespace xmlns="" could not be added as a namespace

Rolf Lear jdom at tuis.net
Tue Jan 24 15:34:56 PST 2012


Hi Leigh.

I have tracked down the issue. It comes from this change I made here:

https://github.com/hunterhacker/jdom/commit/f026e89780b3259fa049fd223ceaacfee16fce65

So, The Saxon code is getting the event fired from the JDOMSource....
... which in turn is breaking the Saxon side of things ... gigo.

In essence I traded one bug for another.

The original bug was that namespaces used by Attributes were being 
'missed' in the SAX Event stream, but now that they are checked, we need 
to ensure that the no-namespace namespace is excluded.

It is an easy fix, but a slower process to get JDOM 1.1.3 out.

Rolf

On 24/01/2012 4:13 PM, Leigh L Klotz Jr wrote:
> Thanks, Rolf.  This is more than enough analysis on your part.  I
> appreciate it.
> Leigh.
>
> On 01/24/2012 12:30 PM, Rolf Lear wrote:
>>
>> Hi Leigh.
>>
>> I am at my office so I can't debug this issue right now... and
>> additionally I have not played with Saxon XSLT code.
>>
>> but, inspecting the JDOM 1.1.2 code it is 'clear' that the Saxon code
>> triggered the following Sax 'events':
>>
>>
>> ...
>> // maybe some other startPrefixMapping(..., ...);
>> startPrefixMapping("", "");  // indicate that the "" prefix is linked to
>> the "" URI
>> startElement("http://example.com/foo", "bar", "bar", attributes);
>> ...
>>
>>
>> This is a broken chain of SAX events.... it is indicating that the ""
>> prefix maps to "" (xmlns=""), but then loads the element in the foo
>> namespace xmlns="http://example.com/foo"
>>
>> In the particular examples you cite there should be exactly one
>> startPrefixMapping("", "") call per document and it should happen before
>> the 'document' start element (or will it be zero calls for "","" since it
>> is assumed... I forget).
>>
>> when the new element processes the 'additional' namespace xmlns="" it
>> finds that the element itself has the "" prefix, but it is mapped to a
>> different URI. Hence the exception.
>>
>> Now, as to why this is different in 1.1.2 vs. 1.1.1 I am not sure.... and
>> that in itself is suspicious....
>>
>> If you have the code in hand you can more easily debug the issue...
>> (easier than me right now...).
>>
>> I can load it up in a few hours time and inspect it too. I suspect that
>> the issue is a Saxon one, but then why the difference between 1.1.1 and
>> 1.1.2 ... I am not sure.
>>
>> Rolf
>>
>>
>>
>> On Tue, 24 Jan 2012 11:26:41 -0800, Leigh L Klotz Jr
>> <leigh.klotz at xerox.com> wrote:
>> > Has anyone encountered this? It doesn't happen with JDOM 1.1.1, but it
>> > does happen with JDOM 1.1.2.
>> >
>> > Vanilla XSLT transform:
>> >
>> > <?xml version="1.0"?>
>> > <xsl:transform version="1.0"
>> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>> > <xsl:template match="*|@*|text()">
>> > <xsl:copy-of select="." />
>> > </xsl:template>
>> > </xsl:transform>
>> >
>> > Document with default namespace change and any attribute on the
>> element:
>>
>> > FAILS:
>> >
>> > <?xml version="1.0" encoding="UTF-8"?>
>> > <description>
>> > <foo xmlns="http://example.com/foo">
>> > <bar x="...">...</bar>
>> > </foo>
>> > </description>
>> >
>> > Document with default namespace change and no attribute on the element:
>> > WORKS:
>> > <?xml version="1.0" encoding="UTF-8"?>
>> > <description>
>> > <foo xmlns="http://example.com/foo">
>> > <bar >...</bar>
>> > </foo>
>> > </description>
>> >
>> > Here's the error:
>> >
>> > org.jdom.IllegalAddException: The namespace xmlns="" could not be added
>> > as a namespace to "bar": The namespace prefix "" collides with the
>> > element namespace prefix
>> >      at org.jdom.Element.addNamespaceDeclaration(Element.java:363)
>> >      at
>> org.jdom.input.SAXHandler.transferNamespaces(SAXHandler.java:714)
>> >      at org.jdom.input.SAXHandler.startElement(SAXHandler.java:563)
>> >      at
>> >
>> net.sf.saxon.event.ContentHandlerProxy.startContent(ContentHandlerProxy.java:366)
>>
>> >      at
>> >
>> net.sf.saxon.event.NamespaceReducer.startContent(NamespaceReducer.java:192)
>>
>> >      at
>> >
>> net.sf.saxon.event.ComplexContentOutputter.startContent(ComplexContentOutputter.java:583)
>>
>> >      at
>> > net.sf.saxon.tree.tiny.TinyElementImpl.copy(TinyElementImpl.java:350)
>> >      at
>> > net.sf.saxon.expr.instruct.CopyOf.processLeavingTail(CopyOf.java:510)
>> >      at
>> > net.sf.saxon.expr.instruct.Template.applyLeavingTail(Template.java:212)
>> >      at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:1032)
>> >      at
>> >
>> net.sf.saxon.trans.TextOnlyCopyRuleSet.process(TextOnlyCopyRuleSet.java:58)
>>
>> >      at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:1020)
>> >      at net.sf.saxon.Controller.transformDocument(Controller.java:1957)
>> >      at net.sf.saxon.Controller.transform(Controller.java:1803)
>> >      at
>> > net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:430)
>> >
>> >
>> > I'm using this code fragment to tell Saxon9 to serialize to JDOM:
>> >
>> >    import net.sf.saxon.s9api.SAXDestination;
>> >    import org.jdom.input.SAXHandler;
>> >    import net.sf.saxon.s9api.Destination;
>> >
>> >    SAXHandler saxHandler = new SAXHandler();
>> >    Destination saxDestination = new SAXDestination(saxHandler);
>> >    xsltTransformer.setSource(new JDOMSource(document));
>> >    xsltTransformer.setDestination(saxDestination);
>> >    xsltTransformer.transform();
>> >
>> > If this isn't a JDOM bug, then I guess it must be a Saxon one.
>> >
>> > Leigh.
>> >
>> > _______________________________________________
>> > To control your jdom-interest membership:
>> > http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
>>
>



More information about the jdom-interest mailing list