Using DOM Parser

Die_SabRina

New Member
I am trying to parse a xml using the below code,i am able to parse it and read the values.But i am not sure how to modify the code to read the node "INFO",i have escaped that node and directly using PARAM as below:XML\[code\]<?xml version="1.0" encoding="UTF-8"?><myxml> <id>23343</id> <INFO> <PARAM> <PARAM_NAME>data</PARAM_NAME> <PARAM_VALUE>345</PARAM_VALUE> </PARAM> <PARAM> <PARAM_NAME>CdataID</PARAM_NAME> <PARAM_VALUE>6788</PARAM_VALUE> </PARAM> </INFO></myxml>\[/code\]and the java code is :\[code\] DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName("PARAM"); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; if (getTagValue("PARAM_NAME",eElement).equals("data")) { String type = getTagValue("PARAM_VALUE", eElement); } } } } catch (Exception e) { e.printStackTrace(); } } private static String getTagValue(String sTag, Element eElement) { NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes(); Node nValue = http://stackoverflow.com/questions/11418885/(Node) nlList.item(0); return nValue.getNodeValue(); }}\[/code\]I want to add INFO node ,how to modify the above code ?
 
Back
Top