XML OUTPUT
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<HelpListResponse>
<HelpList>
<id>16639505</id>
<name>HelpList_Old</name>
<details>HelpList/16639505</details>
</HelpList>
<HelpList>
<id>16641505</id>
<name>Investments to Watch</name>
<details>HelpList/16641505</details>
</HelpList>
<HelpList>
<id>16640505</id>
<name>HelpList_New</name>
<details>HelpList/16640505</details>
</HelpList>
</HelpListResponse>
JAVA CODE for XML Parsing...
xmlFile = new File("xmlFile.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(xmlFile);
I am parsing above xml document and storing it in doc object. For instance, if i need to retrieve name value from first index (ie:"HelpList_Old"), then i use the below statement
doc.getElementsByTagName("name").item(0).getTextContent();
=> This helps me to print "HelpList_Old"
I need couple of things and I am not sure how to go about it… 1) I need to get index value based on the text content of xml. (eg: - If I provide "HelpList_Old", then it should return me index = 0, similarly if i want to get the index of value "HelpList_New" it should return 2)
2) On same lines, if I provide "HelpList_Old", then I want to print its corresponding tag value, in this case “16639505”
Let me know in case I am not clear with my question. Thanks in Advance..