justinshep22
New Member
Using the following I code I am trying to get List of nodes in xml, but the application crashes throwing a saxparser exception.this is the xml I am trying to use\[code\]<?xml version="1.0"?><Root><ResponseCode>1</ResponseCode><ResponseMessage>Reported Successfully</ResponseMessage><ResultSet><Post><id>1</id><title>Garbage Problem near my home</title><comment>We the citizens have been facing the problems of garbage since 2004 , kindly fix it , authorities are concerned</comment><imagepath></imagepath><cordx>24.818688</cordx><cordy>67.029686</cordy><tag>Garbage</tag><userid>1</userid><departmentid>1</departmentid><response></response><createdOn>2013-03-23 14:44:43</createdOn><status>2</status></Post></ResultSet></Root>\[/code\]and this is the code I am trying to use to get from the xml\[code\]InputSource is = new InputSource();is.setCharacterStream(new StringReader(result));XPathFactory factory = XPathFactory.newInstance();XPath xPath = factory.newXPath();String code = xPath.evaluate("/Root/ResponseCode/text()", is);if(code.compareTo("1")==0){ Log.d("Responce Code", code); NodeList nodeList = (NodeList) xPath.evaluate("//Post", is,XPathConstants.NODESET);for(int i=0; i<nodeList.getLength(); i++){ Node n=nodeList.item(i); Element element = (Element) n; Log.d("LIST DATA", element.getElementsByTagName("id").item(0).getTextContent()); }\[/code\]Here is the logcat:\[code\]03-24 12:31:16.357: I/Post service Response(901): <?xml version="1.0"?><Root><ResponseCode>1</ResponseCode><ResponseMessage>Reported Successfully</ResponseMessage><ResultSet><Post><id>1</id><title>Garbage Problem near my home</title><comment>We the citizens have been facing the problems of garbage since 2004 , kindly fix it , authorities are concerned</comment><imagepath></imagepath><cordx>24.818688</cordx><cordy>67.029686</cordy><tag>Garbage</tag><userid>1</userid><departmentid>1</departmentid><response></response><createdOn>2013-03-23 14:44:43</createdOn><status>2</status></Post></ResultSet></Root>03-24 12:31:16.498: D/Responce Code(901): 103-24 12:31:16.537: W/System.err(901): org.xml.sax.SAXParseException: Unexpected end of document03-24 12:31:16.537: W/System.err(901): at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:129)03-24 12:31:16.537: W/System.err(901): at org.apache.xpath.jaxp.XPathImpl.evaluate(XPathImpl.java:474)03-24 12:31:16.548: W/System.err(901): at com.teamgreen.greenit.HistoryActivity$1.run(HistoryActivity.java:69)03-24 12:31:16.548: W/System.err(901): --------------- linked to ------------------03-24 12:31:16.548: W/System.err(901): javax.xml.xpath.XPathExpressionException: org.xml.sax.SAXParseException: Unexpected end of document03-24 12:31:16.577: W/System.err(901): at org.apache.xpath.jaxp.XPathImpl.evaluate(XPathImpl.java:479)03-24 12:31:16.577: W/System.err(901): at com.teamgreen.greenit.HistoryActivity$1.run(HistoryActivity.java:69)03-24 12:31:16.587: W/System.err(901): Caused by: org.xml.sax.SAXParseException: Unexpected end of document03-24 12:31:16.587: W/System.err(901): at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:129)03-24 12:31:16.587: W/System.err(901): at org.apache.xpath.jaxp.XPathImpl.evaluate(XPathImpl.java:474)03-24 12:31:16.607: W/System.err(901): ... 1 more\[/code\]