它不是'&'
我使用 SAXParser 对象来解析实际的 XML。
这通常通过将 URL 传递给 XMLReader.Parse 方法来完成。因为我的 XML 来自对 Web 服务的 POST 请求,所以我将该结果保存为字符串,然后使用 StringReader / InputSource 将此字符串反馈给 XMLReader.Parse 方法。
但是,在 XMLstring 的第 2001 个字符处发生了一些奇怪的事情。
文档处理程序的“字符”方法在 startElement 和 endElement 方法之间被调用两次,有效地将我的字符串(在本例中为项目标题)分成两部分。因为我在我的角色方法中实例化对象,所以我得到了两个对象而不是一个。
这条线,大约 2000 个字符到字符串中会触发“字符”两次,在“Lower”和“Level”之间中断
<title>SUMC-BOOKSTORE, LOWER LEVEL RENOVATIONS</title>
当我绕过 StringReader / InputSource 解决方法并将平面 XML 文件提供给 XMLReader.Parse 时,它工作得非常好。
关于 StringReader 和/或 InputSource 的某些东西以某种方式搞砸了。
这是我通过 SAXParser 获取和解析 XML 字符串的方法。
public void parseXML(String XMLstring) {
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
xr.setContentHandler(this);
// Something is happening in the StringReader or InputSource
// That cuts the XML element in half at the 2001 character mark.
StringReader sr = new StringReader(XMLstring);
InputSource is = new InputSource(sr);
xr.parse(is);
} catch (IOException e) {
Log.e("CMS1", e.toString());
} catch (SAXException e) {
Log.e("CMS2", e.toString());
} catch (ParserConfigurationException e) {
Log.e("CMS3", e.toString());
}
}
当我在 XML 字符串中达到这一点时,我将非常感谢有关如何不让“字符”触发两次的任何想法。
或者,向我展示如何使用 POST 请求并仍然将 URL 传递给 Parse 函数。
谢谢你。