Issue Details (XML | Word | Printable)

Key: XALANJ-2219
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Brian Minchau
Reporter: Jesse Glick
Votes: 1
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
XalanJ2

Namespace of child element written incorrectly as root namespace

Created: 25/Oct/05 07:38 AM   Updated: 14/Dec/07 07:12 AM
Return to search
Component/s: Serialization
Affects Version/s: 2.7, 2.6, 2.5
Fix Version/s: 2.7.1

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works jira2219.patch5.txt 2006-10-30 03:33 AM Brian Minchau 8 kB
Text File Licensed for inclusion in ASF works ToStream.patch2.txt 2006-06-02 11:17 PM Brian Minchau 3 kB
Text File Licensed for inclusion in ASF works ToStream.patch4.txt 2006-07-17 08:57 PM Brian Minchau 3 kB
Environment:
Linux m2 2.6.13-1.1532_FC4 #1 Thu Oct 20 01:30:08 EDT 2005 i686 i686 i386 GNU/Linux
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)
Issue Links:
Blocker
 
Reference

Xalan info: PatchAvailable
Reviewer: Henry Zongaro
Resolution Date: 31/Oct/06 08:54 PM


 Description  « Hide
Run this class:

---%<---
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
public class Test {
    private static final String IDENTITY_XSLT_WITH_INDENT =
            "<xsl:stylesheet version='1.0' " +
            "xmlns:xsl='http://www.w3.org/1999/XSL/Transform' " +
            "xmlns:xalan='http://xml.apache.org/xslt' " +
            "exclude-result-prefixes='xalan'>" +
            "<xsl:output method='xml' indent='yes' xalan:indent-amount='4'/>" +
            "<xsl:template match='@*|node()'>" +
            "<xsl:copy>" +
            "<xsl:apply-templates select='@*|node()'/>" +
            "</xsl:copy>" +
            "</xsl:template>" +
            "</xsl:stylesheet>";
    public static void main(String[] args) throws Exception {
        String data = "<root xmlns='root'/>";
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(data)));
        /*
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation().createDocument("root", "root", null);
         */
        doc.getDocumentElement().appendChild(doc.createElementNS("child", "child"));
        Transformer t = TransformerFactory.newInstance().newTransformer(
                new StreamSource(new StringReader(IDENTITY_XSLT_WITH_INDENT)));
        Source source = new DOMSource(doc);
        Result result = new StreamResult(System.out);
        t.transform(source, result);
    }
}
---%<---

Just using plain JDK 5.0 JAXP, I get the expected

---%<---
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="root">
    <child xmlns="child"/>
</root>
---%<---

If I add Xalan-J to the classpath, I get

---%<---
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="root">
    <child xmlns="root"/>
</root>
---%<---

Note the incorrect namespace on the child element.

This is true in Xalan 2.5.2, 2.6.0, 2.7.0, and dev builds (xalan-gump-24102005.jar).

Prevents Xalan from being bundled with the NetBeans IDE, as it causes incorrectly written project metadata:

http://www.netbeans.org/issues/show_bug.cgi?id=66563

If you use newTransformer() with no stylesheet the problem goes away (though of course you lose indentation unless it is readded using setOutputProperty). Also if the Document is created in memory rather than parsed (see commented-out code) the problem goes away.

Does not seem to be reproducible in JDK 6, I don't know why.

Inclusion of the bundled Xerces in the classpath does not appear to make any difference.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Brian Minchau made changes - 02/Jun/06 11:09 PM
Field Original Value New Value
Assignee Brian Minchau [ minchau@ca.ibm.com ]
Brian Minchau made changes - 02/Jun/06 11:17 PM
Attachment ToStream.patch2.txt [ 12334953 ]
Brian Minchau made changes - 02/Jun/06 11:18 PM
Henry Zongaro made changes - 21/Jun/06 12:40 AM
Xalan info [PatchAvailable]
Brian Minchau made changes - 21/Jun/06 02:31 AM
Fix Version/s Latest Development Code [ 10863 ]
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Brian Minchau made changes - 21/Jun/06 02:45 AM
Link This issue relates to XALANJ-2302 [ XALANJ-2302 ]
Brian Minchau made changes - 21/Jun/06 02:46 AM
Link This issue is related to XALANJ-2302 [ XALANJ-2302 ]
Brian Minchau made changes - 17/Jul/06 08:57 PM
Attachment ToStream.patch4.txt [ 12337059 ]
Brian Minchau made changes - 15/Oct/06 05:05 PM
Resolution Fixed [ 1 ]
Status Resolved [ 5 ] Reopened [ 4 ]
Brian Minchau made changes - 30/Oct/06 03:33 AM
Attachment jira2219.patch5.txt [ 12343856 ]
Brian Minchau made changes - 31/Oct/06 08:54 PM
Resolution Fixed [ 1 ]
Status Reopened [ 4 ] Resolved [ 5 ]
Vasily Zakharov made changes - 21/Feb/07 09:29 PM
Link This issue blocks HARMONY-3221 [ HARMONY-3221 ]