Bugs item #1193537, was opened at 2005-05-02 09:24 Message generated for change (Comment added) made by tony_robertson You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=116035&aid=1193537&group_id=16035
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: duplicate namespaces output in XMLWriter Initial Comment: When using SAXWriter to output a SAX stream from TRaX, SAXWriter outputs duplicate namespaces. This appears to be because the namespaces appear in the SAX stream both as prefix mappings and as attributes. (I think the dual-representation of namespaces also ocurrs when the SAX namespace-prefix feature is enabled in the SAX parser.) The test case below highlights the problem, and the XMLWriter.patch is one possible fix. [Tested on JDK1.4.2_06.] import junit.framework.TestCase; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; import org.xml.sax.InputSource; import javax.xml.transform.*; import javax.xml.transform.sax.*; import javax.xml.transform.stream.*; import java.io.*; /** * Tries to exercise a bug where namespace declarations are output twice, * when using JAXP SAX transform with Dom4j XMLWriter. */ public class TestJAPXDom4jSerialize extends TestCase { String xml = "<test:test xmlns:test='testns' xmlns='abc'/>"; String xslt = "<?xml version=\1.0\ encoding=\iso-8859-1\?>\n" + "<xsl:stylesheet xmlns:xsl=\http://www.w3.org/1999/XSL/Transform\ version=\1.0\>\n" + "<xsl:template match=\/\>\n" + " <xsl:copy-of select=\.\/>\n" + "</xsl:template>\n" + "</xsl:stylesheet>"; public void testXSLTNamespace() throws TransformerException { SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); TransformerHandler handler = factory.newTransformerHandler(new StreamSource(new StringReader(xslt))); Transformer tx = handler.getTransformer(); StringWriter sw = new StringWriter(); OutputFormat of = OutputFormat.createCompactFormat(); of.setSuppressDeclaration(true); XMLWriter writer = new XMLWriter(sw, of); tx.transform(new SAXSource(new InputSource(new StringReader(xml))), new SAXResult(writer)); assertEquals("<test:test xmlns:test=\testns\ xmlns=\abc\></test:test>", sw.toString()); } } ---------------------------------------------------------------------- Comment By: Tony Robertson (tony_robertson) Date: 2005-08-22 11:21 Message: Logged In: YES user_id=1332772 I have also found this bug causes trouble in jakarta- commons "Jelly", which uses the DOM4J XMLWriter. There is a reference to "Fixed bug in XMLWriterwhere namespace declarations were duplicated" by "maartenc" in the change notes for "Release 1.5-beta-1 - 2004-03-25", but that fix seems to address the writeAttributes(Element) method which is used by the public void writeOpen(Element element) method. It doesn't address the bug described here. The patch attached to this bug report looks like it will fix the problem, so I vote that it gets included. Regards. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=116035&aid=1193537&group_id=16035 ------------------------------------------------------- SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf _______________________________________________ dom4j-dev mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-dev