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 2005/04/04 21:51:17 UTC

[jira] Commented: (XALANJ-2091) Namespace attributes not added as attributes when using TransformerIdentityImpl

     [ http://issues.apache.org/jira/browse/XALANJ-2091?page=comments#action_62134 ]
     
Brian Minchau commented on XALANJ-2091:
---------------------------------------

The patch needs careful consideration. In a note to xalan-j-users David Bertoni wrote:
> 
> 
> That's because namespace declaration are represented in the data model as 
> namespaces nodes, not attribute nodes:
> 
> 
> http://www.w3.org/TR/xpath#namespace-nodes
> 
> Dave
> 

I too have concerns about the patch. In a serialized XML document (a stream of characters, usually written to a file) namespace nodes appear as attributes, xmlns:prefix="someURI".
But that doesn't mean that they actually ARE attributes in the data model.  It seems to me with Felix suggested change that the DOM would have both a namespace node and an attribute for the prefix/uri mapping, and I'm not sure that having both is correct.



> Namespace attributes not added as attributes when using TransformerIdentityImpl
> -------------------------------------------------------------------------------
>
>          Key: XALANJ-2091
>          URL: http://issues.apache.org/jira/browse/XALANJ-2091
>      Project: XalanJ2
>         Type: Bug
>   Components: transformation
>     Versions: CurrentCVS
>     Reporter: Felix Röthenbacher
>  Attachments: TransformerIdentityImpl.java.diff
>
> Namespace attributes are not added as attributes to the resulting
> DOM tree when using TransformerIdentityImpl. The problem is, that
> the namespace-prefix feature is not set to true and therefore the
> namespace attributes are not added. This does not conform to the
> DOM spec saying that also namespace attributes may be handled as
> normal attributes.
> I will attach a patch which fixes the issue by calling
>            reader.setFeature("http://xml.org/sax/features/namespace-prefixes",
>                              true);
> of the XMLReader.
> The following code shows the problem:
> The input XML document looks like this:
> <?xml version="1.0"?>
> <test xmlns:testns="http://testns.org" testns:testattr="3"/>
> And the code used to extract the namespace attributes is as follows:
>   FileInputStream fis = new FileInputStream("test.xml");
>   Transformer trfs = TransformerFactory.newInstance().newTransformer();
>   StreamSource ss = new StreamSource(fis);
>   DOMResult dr = new DOMResult();
>   trfs.transform(ss, dr);
>   Document doc = (Document)dr.getNode();
>   Node node = doc.getFirstChild();
>   System.out.println("First node: " + node.getLocalName());
>   NamedNodeMap nodes = node.getAttributes();
>   for (int i=0; i<nodes.getLength(); i++) {
>     System.out.println("  Attribute: " + nodes.item(i).getLocalName());
>   }
> Finally, the the output looks like this:
>   First node: test
>   Attribute: testattr
> instead of the expected output:
>   First node: test
>   Attribute: testns
>   Attribute: testattr

-- 
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
-
If you want more information on JIRA, or have a bug to report 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