Parsing XML File using Jdom and SAX Parser

james9r9r

New Member
I have a XML in the format:\[code\]<response><result name="response" numFound="295" start="0"><doc><str name="Content">...</str><str name="Latitude">36.48617</str><str name="Longitude">-89.97065</str><str name="id">00000001 pages 1-249.pdf</str></doc><doc><str name="Content">...</str><str name="Latitude">33.59927</str><str name="Longitude">-86.69304</str><str name="id">100-449923 section 26 -114.pdf</str></doc><doc>\[/code\]I need to find the values of Content, Latitude and Longitude in variable. So far my code is:\[code\]SAXBuilder sax=new SAXBuilder();Document doc= (Document) sax.build(new StringReader(xmlstr));Element rootElem=doc.getRootElement();out.println("rootElem = " + rootElem.toString());Element res=rootElem.getChild("result");List docs=res.getChildren("doc");for(int i=0;i<docs.size();i++){ out.println("docsSize = " + docs.size()); Element row= (Element)docs.get(i); //List strs= docs(i).getChildren("str"); List strs=row.getChildren("str"); for(int j=0;j<strs.size();j++){ out.println("strs = " + strs.size()); //out.println(strs.get(j).getValue()); List column = (List)strs.get(j); if(column.getAttribute("name").getValue()=='Content') { out.println("Hi"); out.println(column.getAttribute("name").getValue()); out.println("Bi"); } //String Content = column.getAttribute("name").get(1).getValue(); //String value = http://stackoverflow.com/questions/10379185/column.getText(); //out.println("Content = " + Content); //out.println("value = "http://stackoverflow.com/questions/10379185/+ value); } //out.println(content); break;}}catch(Exception e){ out.println(e);} \[/code\]But still i am not able to get values f Latitude and Longitude, even though i get size of the array they are in. Can you pls suggest the same
 
Back
Top