-
Search with DOM
Hi i have a code in Eclipse thath read an xml file and write the values into array:
Code:
String title="";
String description="";
String type="";
String media="";
String url="";
String lastupdate="";
String author="";
String complete[][]=null;
fileDownload();
try{
File file = new File("test.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
NodeList nodeLst = doc.getElementsByTagName("doc");
complete=new String[nodeLst.getLength()][8];
for (int s = 0; s < nodeLst.getLength(); s++) {
Node fstNode = nodeLst.item(s);
if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
title= GetValue(fstNode, "title" );
description= GetValue(fstNode, "description" );
type= GetValue(fstNode, "type" );
media= GetValue(fstNode, "media" );
url= GetValue(fstNode, "url" );
lastupdate= GetValue(fstNode, "lastupdate" );
author= GetValue(fstNode, "author" );
complete[s][0]="";
complete[s][1]=title;
complete[s][2]=description;
complete[s][3]=type;
complete[s][4]=media;
complete[s][5]=url;
complete[s][6]=lastupdate;
complete[s][7]=author;
}
}
} catch (Exception e) {
e.printStackTrace();
}
Now i need to retrieve only certain values, for example title= "BOOK" and write the array only with those node. I try this with DOM function without solution, can anyone help me ?
Thanks