Get Attribute of a NodeList?
843834Aug 3 2006 — edited Aug 3 2006Can anyone help me get the 'user_agent' attribute of the TagName 'device' in the following code. I'm sure it's not that hard but I can get it.
Many thanks in advance.
// Create DOM XML document factory
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(new File("wurfl.xml"));
// normalize text representation
doc.getDocumentElement().normalize();
System.out.println("Root element of the doc is " +
doc.getDocumentElement().getNodeName());
NodeList listOfDevices = doc.getElementsByTagName("device");
int totalDevices = listOfDevices.getLength();
System.out.println("Total no of devices: " + totalDevices);
for(int s=0; s<listOfDevices.getLength() ; s++){
// need to get the attribute called user_agent from the 'device' tag here
}