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

Namespaces as attributes fails

Hi

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

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

Any ideas what might go wrong?

Thanks

Felix

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