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

Reply via email to