我在下面有xml要解析。
<body>
<body.content>
<p>This is testing content.</p>
<p>This is testing content.This is testing content.This is testing content.This is testing content.This is testing content.This is testing content.This is testing content.This is testing content.This is testing content.This is testing content.</p>
</body.content>
</body>
我有这个 xml 的解析器方法。
bodyTag.getChild(body_content).setEndTextElementListener(new EndTextElementListener() {
@Override
public void end(String body) {
System.out.println(body);
}
});
我的问题是当我解析这个xml时,我得到了以下异常。
10-06 15:39:21.976: E/AndroidRuntime(1110): 由以下原因引起: java.lang.RuntimeException: android.sax.BadXmlException: 第 86 行: 在名为"body.content"的文本元素中遇到混合内容。
问题是 sax 解析器无法解析 html <p>
标记。我想知道有没有办法通过萨克斯解析器解析html content
。
谢谢
你可以使用 Jsoup 库: http://jsoup.org/用 Html/xml 标签处理非常容易..
试试这个。
<content><![CDATA[Your stuff here with all the <em>HTML</em> tags you can think of.]]></content>
我认为此链接易于理解,因此对您有所帮助。