I am trying to parse the XML file to get the attributes of a particular tag. Below is my XML file-
<?xml version="1.0" encoding="UTF-8"?>
<app hash='nv' name='Tech' package='1.0' version='13' filesize='200' create_date='01-03-1987' upate_date='07-09-2013' >
<url>
<name>RJ</name>
<score>10</score>
</url>
<url>
<name>ABC</name>
<score>20</score>
</url>
</app>
I am trying to get hash, name, package, version, filesize, create_date, update_date value from the above XML file.
Below is my code in which I am trying to parse the above XML file but I am not sure how to get the above required attributes from the app
tag?
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
InputStream is = request.getInputStream();
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
doc.getDocumentElement().normalize();
System.out.println("root of xml file" + doc.getDocumentElement().getNodeName());
//get hash, name, package value from the app tag in the XML file
} catch (Exception e) {
System.out.println(e);
}
Can anyone please help me with this?