tags:

views:

12

answers:

1

I'm trying to print out an attribute value with the following code:

ArrayList arrayList=new ArrayList(); 
String  = "tagToFind";
Node n = node.getParentNode();
String printOut = "";
while (n != null && !n.getNodeName().equals(tagToFind)) {   
    n = n.getParentNode();
}

if (n != null){
    arrayList.add(n.getNodeValue());
    out.println(n.getAttribute("attributeName");
}

But on the out.println(n.getAttribute("attributeName"); I get a "The method getAttribute(String) is undefined for the type Node" error. I am assuming because n is a node and not a node list. Is there an alternative I could use? Or a way around this issue?

A: 

Javadoc

This method does not exist. I never used this API, but I guess you could do it with

Attr yourAttribute = (Attr)(n.getAttributes().getNamedItem("attributeName"));
mdrg