You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Felix Röthenbacher <fe...@wyona.com> on 2005/04/04 00:10:41 UTC

Namespaces as attributes fails

Hi

I try to get the namespaces of the root node as attributes but it
fails:

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

The input XML document looks like this:

<?xml version="1.0"?>
<test xmlns:testns="http://testns.org" testns:testattr="3"/>

And the output looks like this:

First node: test
Attribute: testattr

instead of the expected output:

First node: test
Attribute: testns
Attribute: testattr

Any ideas what might go wrong?

Thanks

Felix

Re: Namespaces as attributes fails

Posted by Felix Röthenbacher <fe...@wyona.com>.
david_n_bertoni@us.ibm.com wrote:
>>I try to get the namespaces of the root node as attributes but it
>>fails:
> 
> 
> 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
> 
Hi Dave

Thanks for your answer. Now I'm a little bit confused because

http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#Namespaces-Considerations

states, that

"... As far as the DOM is concerned, special attributes used for
declaring XML namespaces are still exposed and can be manipulated just
like any other attribute. ..."

With that in mind and the fact, that the Xalan version used with Sun's
JDK works in that manner I filed a bug report:

http://issues.apache.org/jira/browse/XALANJ-2091

I hope that I'm on the right path because there is clearly an
incompatibility between the Xalan trunk and the Xalan used in
the JDK.

- Felix


Re: Namespaces as attributes fails

Posted by da...@us.ibm.com.
> I try to get the namespaces of the root node as attributes but it
> fails:

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