Bugs item #1193537, was opened at 2005-05-01 16:24
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=116035&aid=1193537&group_id=16035

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());
    }
}




----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=116035&aid=1193537&group_id=16035


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20
_______________________________________________
dom4j-dev mailing list
dom4j-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-dev

Reply via email to