parse XML

I am wanting to write something that can parse an xml file. The file I want to read is in the format of:




data I want to read

This code:

System.out.println("Root element " + doc.getDocumentElement().getNodeName());

Gives the output:

Root element container

I was expecting:

Root element root


Can someone please point me in the right direction.

Comments

  • It seems like getNodeName for an Element is returning the same as getTagName. If you want to get the value of the "name" attribute, you have to use getAttribute.

    For example, getAttribute("name")
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion