If you are using the DOM parser in
Java, the following approach will get you there -
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import java.io.File;
import org.w3c.dom.*;
public class order{
public static int depth;
public static void showAttrValue(Element element,
String attrName)
{
System.out.println("Element::"+element.getNodeName()+"->"+"Attr::"+attrName+"->"+
"Value::"+element.getAttribute(attrName));
}
public static void main (String args[]) {
File docFile = new File("bb.xml");
Document
doc = null;
NamedNodeMap nnMap = null;
int i;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
dbf.setExpandEntityReferences(false);
DocumentBuilder docb = dbf.newDocumentBuilder();
doc = docb.parse(docFile);
Element root = doc.getDocumentElement();
depth=0;
// get all the commufuncdef elements
NodeList nList = doc.getElementsByTagName("commufuncdef");
for(i=0; i<nList.getLength(); i++)
{
showAttrValue((Element)nList.item(i), "commufuncdefCode");
}
//recurseNodes(root);
}
catch (DOMException de)
{
System.out.println("DOM Exception ::"+de.toString());
}
catch (Exception e)
{
System.out.println("EXCEPTION::"+e.toString());
System.out.println(e.getClass());
}
}
}
Now that you know how to access the attributes, we can react in whatever way we want by writing some code.