当我记录被调用的XML文件的值时,文件每次都在同一个地方结束。它将不完整的数据保存为字符串,然后将其传递给我的XMLfromString函数,该函数出错并显示异常。 (见下面的错误)
我想知道是否有任何我需要更改以确保顶部读取整个文件。
String xml = XMLfunctions.getXML(items);
Document doc = XMLfunctions.XMLfromString(xml);
public static String getXML(String roomID)
{
Log.d(TAG, roomID + "PASSED");
String line = null;
try
{
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpPost = new HttpGet("http://mywebsite.com/xml_data/" + roomID + "_meeting_info.xml?id=cacheSTOP3");
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
line = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
} catch (MalformedURLException e) {
line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
} catch (IOException e) {
line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
}
Log.d(TAG, line);
return line;
}
public final static Document XMLfromString(String xml){
Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
doc = db.parse(is);
} catch (ParserConfigurationException e) {
System.out.println("XML parse error: " + e.getMessage());
return null;
} catch (SAXException e) {
System.out.println("Wrong XML file structure: " + e.getMessage());
return null;
} catch (IOException e) {
System.out.println("I/O exeption: " + e.getMessage());
return null;
}
return doc;
}
我收到的错误消息是:
11-21 11:11:55.456: INFO/System.out(282): Wrong XML file structure: unterminated entity ref (position:ENTITY_REF &@211:21 in java.io.StringReader@44f6a130)
非常感谢任何帮助。
答案 0 :(得分:0)
检查你的xml,是否正确,是否有任何关闭的标签。如果可能的话,告诉我们哪一行是282,并发布你的xml。