xml – How to print the value of an attribute in jsp/dom – Education Career Blog

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){

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?



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"));

Leave a Comment