我正在尝试使用 DOM 解析 XML 提要。当节点看起来像这样时:
<title>'Star Wars' May the force live</title>
返回的 XML 只是 ' 然后解析器继续到下一个节点。
这是我解析它的方式:
NodeList list = node.getChildNodes();
for (int j=0; j<list.getLength(); j++) {
Node innerItem = list.item(j);
String name = innerItem.getNodeName();
if (name.equalsIgnoreCase("title")) {
vo.setTitle(innerItem.getFirstChild().getNodeValue());
}
}
我该如何解决这个问题?代码在 Android 4 中解析良好,但在 Android 2.3.3 中失败
最佳答案
看起来您的问题与这个问题非常相似:android decoding html in xml file
似乎 HTML 字符破坏了 DOM 解析器,因此无法从 xml 实体中获取字符串。有一个 HTML 函数可以解析字符串中的 HTML。
TextView tv;
String s = "<quote>'Star Wars' May the force live</quote>";
tv.setText(HTML.fromHtml(s));
输出:
"Star Wars" May the force live
然而,似乎 DOM 没有获取要转换的字符串,因此以下文章可能有用:Using XPATH and HTML Cleaner to parse HTML/XML
关于android - 将带撇号的 XML 解析为 ' 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11997131/