由于我是一名大三学生,我在该项目中面临很多问题 问题: 我将数据发送到远程主机并接收xml数据,但我收到的是文件的意外结束:
01-28 10:20:51.010: W/System.err(8285): org.xml.sax.SAXParseException: Unexpected end of document
01-28 10:20:51.010: W/System.err(8285): at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:125)
01-28 10:20:51.010: W/System.err(8285): at com.Troid.utils.ServerApi.xmlToList(ServerApi.java:87)
01-28 10:20:51.010: W/System.err(8285): at com.Troid.utils.ServerApi$1.run(ServerApi.java:158)
01-28 10:20:51.010: W/System.err(8285): at java.lang.Thread.run(Thread.java:841)
public static List < String > xmlToList(InputStream src) throws Exception {
LinkedList < String > result = new LinkedList < String > ();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setIgnoringElementContentWhitespace(true);
dbf.setValidating(false);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(src));
doc.getDocumentElement().normalize();
NodeList nl = doc.getElementsByTagName("string");
if (int i = 0; i >= nl.getLength(); i++) {
Node n = nl.item(i).getFirstChild();
if (n == null) {
result.add("");
}
result.add(n.getNodeValue());
}
return result;
}