You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Brian Minchau (JIRA)" <xa...@xml.apache.org> on 2007/10/09 19:35:50 UTC

[jira] Created: (XALANJ-2406) Unexpected namespace mappings using identity Transformer with DOM flavour

Unexpected namespace mappings using identity Transformer with DOM flavour
-------------------------------------------------------------------------

                 Key: XALANJ-2406
                 URL: https://issues.apache.org/jira/browse/XALANJ-2406
             Project: XalanJ2
          Issue Type: Bug
          Components: DOM, Serialization
            Reporter: Brian Minchau
             Fix For: The Latest Development Code


This isn't exacly a bug, but it is against the serialization "philosophy".

The serializer stage tries to write out a minimal set of namespace mappings. For example if <a> has child <b> and both elements have the namespace node that maps prefix "prex" to URI "uri-x" then it tries to serializer the document as:
   <a xmlns:prex='uri-x'><b/></a>
rather than as:
   <a xmlns:prex='uri-x'><b xmlns:prex='uri-x' /></a>

It isn't that the second form is wrong, it is just that due to the XML standard <b> inherits its parent namespace nodes or mappings. The problem with the second form is that things can get pretty messy when there are a number of namespace nodes and also a deep ancestor tree.  Messy and potentially a preformance problem with large (lots of characters) output XML.

Here is a testcase showing this problem:

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.dom.DOMSource;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;

import java.io.*;
import java.util.Properties;

public class Test {

    private static final String XML_SOURCE =
        "<doc xmlns:foo='foo'>" +
        "<a xmlns:foo='foo'/>" +
        "</doc>";
    
  
       public static void main(String[] args) throws Exception
       {
              
              DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
        dfactory.setNamespaceAware(true);

        DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
        Node xmlDOM = docBuilder.parse(new InputSource(new StringReader(XML_SOURCE)));
        
        String key = "javax.xml.transform.TransformerFactory";
        String value = org.apache.xalan.processor.TransformerFactoryImpl.class.getName();
        Properties props = System.getProperties();
        props.put(key, value);
        System.setProperties(props);
        
              Transformer t = TransformerFactory.newInstance().newTransformer();
              t.transform(new DOMSource(xmlDOM), new StreamResult(System.out));
       }

}

Expected result:
<?xml version="1.0" encoding="UTF-8"?><doc xmlns:foo="foo"><a/></doc>
Actual result:
<?xml version="1.0" encoding="UTF-8"?><doc xmlns:foo="foo"><a xmlns:foo="foo"/></doc>





-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Commented: (XALANJ-2406) Unexpected namespace mappings using identity Transformer with DOM flavour

Posted by "Christine Li (JIRA)" <xa...@xml.apache.org>.
    [ https://issues.apache.org/jira/browse/XALANJ-2406?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12533522 ] 

Christine Li commented on XALANJ-2406:
--------------------------------------

The patch looks good to me. It resolved the reported problem.

> Unexpected namespace mappings using identity Transformer with DOM flavour
> -------------------------------------------------------------------------
>
>                 Key: XALANJ-2406
>                 URL: https://issues.apache.org/jira/browse/XALANJ-2406
>             Project: XalanJ2
>          Issue Type: Bug
>          Components: DOM, Serialization
>            Reporter: Brian Minchau
>             Fix For: The Latest Development Code
>
>         Attachments: serializer.TreeWalker.patch5.txt
>
>
> This isn't exacly a bug, but it is against the serialization "philosophy".
> The serializer stage tries to write out a minimal set of namespace mappings. For example if <a> has child <b> and both elements have the namespace node that maps prefix "prex" to URI "uri-x" then it tries to serializer the document as:
>    <a xmlns:prex='uri-x'><b/></a>
> rather than as:
>    <a xmlns:prex='uri-x'><b xmlns:prex='uri-x' /></a>
> It isn't that the second form is wrong, it is just that due to the XML standard <b> inherits its parent namespace nodes or mappings. The problem with the second form is that things can get pretty messy when there are a number of namespace nodes and also a deep ancestor tree.  Messy and potentially a preformance problem with large (lots of characters) output XML.
> Here is a testcase showing this problem:
> import javax.xml.parsers.DocumentBuilder;
> import javax.xml.parsers.DocumentBuilderFactory;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.Transformer;
> import javax.xml.transform.stream.StreamResult;
> import javax.xml.transform.dom.DOMSource;
> import org.w3c.dom.Node;
> import org.xml.sax.InputSource;
> import java.io.*;
> import java.util.Properties;
> public class Test {
>     private static final String XML_SOURCE =
>         "<doc xmlns:foo='foo'>" +
>         "<a xmlns:foo='foo'/>" +
>         "</doc>";
>     
>   
>        public static void main(String[] args) throws Exception
>        {
>               
>               DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
>         dfactory.setNamespaceAware(true);
>         DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
>         Node xmlDOM = docBuilder.parse(new InputSource(new StringReader(XML_SOURCE)));
>         
>         String key = "javax.xml.transform.TransformerFactory";
>         String value = org.apache.xalan.processor.TransformerFactoryImpl.class.getName();
>         Properties props = System.getProperties();
>         props.put(key, value);
>         System.setProperties(props);
>         
>               Transformer t = TransformerFactory.newInstance().newTransformer();
>               t.transform(new DOMSource(xmlDOM), new StreamResult(System.out));
>        }
> }
> Expected result:
> <?xml version="1.0" encoding="UTF-8"?><doc xmlns:foo="foo"><a/></doc>
> Actual result:
> <?xml version="1.0" encoding="UTF-8"?><doc xmlns:foo="foo"><a xmlns:foo="foo"/></doc>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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