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

Leigh L Klotz Jr leigh.klotz at xerox.com
Tue Jan 24 11:26:41 PST 2012


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.



More information about the jdom-interest mailing list