[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xalan-dev
Subject:    [jira] Created: (XALANJ-2302) Prefix collision bug during
From:       "Brian Minchau (JIRA)" <xalan-dev () xml ! apache ! org>
Date:       2006-06-20 19:27:30
Message-ID: 19911641.1150831650489.JavaMail.jira () brutus
[Download RAW message or body]

Prefix collision bug during serialization
-----------------------------------------

         Key: XALANJ-2302
         URL: http://issues.apache.org/jira/browse/XALANJ-2302
     Project: XalanJ2
        Type: Bug

    Reporter: Brian Minchau


During work on xalanj-2219, which Henry Zongaro reviewed, he found a related bug \
where an attribute added through manipulation of a DOM would cause a prefix \
collision.

His testcase was similar to the one in xalanj-2219. First create an element named \
"p:child" in namespace URI "child". When serialized this element would look like \
this: <p:child xmlns:p='child' />

Then to this DOM Element, add an attribute named q:attr with value 'val' and have \
attribute in the namespace 'moo'.  When serialized this element would look like this:
<p:child xlmns:p='child'  q:attr='val'  xmlns:q='moo' />

Now to cause the collision have the name of the attribute be 'p:attr'. The prefix p \
must map to both 'child' and to 'moo'. The only way out is to NOT use p for one of \
the prefixes, and to pick a new one that is not mapped, something like this: <p:child \
xmlns:p='child'  ns0:attr='val' xmlns:ns0='moo' />

Henry's testcase, much like the one in xalanj-2219 is this:
-------------------------------------------------------------------------------
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.w3c.dom.Element;
import org.xml.sax.InputSource;
public class j2219b {
    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 = "<p:root xmlns:p='root'/>";
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        Document doc = dbf.newDocumentBuilder().parse(new InputSource(new \
StringReader(data)));  Element e = doc.createElementNS("child", "p:child");
        e.setAttributeNS("moo", "p:attr", "val");
        doc.getDocumentElement().appendChild(e);
        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);
    }
}

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

Now there is a problem. When serialized the same prefix cannot be used

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic