This discussion is archived
3 Replies Latest reply: Jan 29, 2009 12:08 PM by 843785 RSS

xml parsing - how access attributes?

843785 Newbie
Currently Being Moderated

I have been working on this for 3 hours, but I can't seem to find out how to do this.

I have written a little program that gets values from an xml file.
Now I also need to get certain attribute, but I can't get it right.

This is my code:
private static boolean isMyItem(Node item) {
    return isItem("MyItem", item);

private void findItems(Node document) {
   List<Node> transactions = findAllChildNodes("Transaction", document);
        for (Node node : transactions) {
            for (Node item : findAllChildNodes("Item", node)) {
                if (isMyItem(item)) {
                            System.out.println( findChildNode("ItemContent", item).getTextContent());
my xml file structure is:
          <Description Language="EN">MyItem</Description>
        <ItemContent DataType="NM" Units="L" Ref="6">5</ItemContent>
Basically what I need is to get the attribute Ref (6 in this example).
Who can help?

Edited by: vampke on Jan 28, 2009 7:30 AM