如何使用android的SAX解析器解析html嵌套标记

时间:2012-05-19 18:29:09

标签: android xml-parsing sax

我的xml中有这个标记:

<description><![CDATA[<div><b>Location:</b> PUMBA Auditorium - University of Pune</div>
<div><b>Start Time:</b> 5/15/2012 11:00 AM</div>
<div><b>End Time:</b> 5/15/2012 2:00 PM</div>
<div><b>Description:</b> <div>General B. C. Joshi Memorial Lecture 2012- Perspective on War in the 21st Century - By Lt. Gen. A. K. Singh</div></div>
<div><b>Attachments:</b> <a href="http://uopnews.unipune.ac.in/Lists/Calendar/Attachments/14/bcjoshi2012[1].pdf">http://uopnews.unipune.ac.in/Lists/Calendar/Attachments/14/bcjoshi2012[1].pdf</a><br><a href=""></a></div>
]]></description>

我需要删除&#34; <div><b>&#34;我想只显示内容。 我应该为此做些什么。 请帮我。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

你基本上必须再次解析。 <![CDATA[]]>之间包含的所有内容都被解析器视为字符数据(文本)。假设此文本是有效的xhtml,您可以将字符串转换为ByteArrayInputStream并将其提供给解析器。

Android还为Html类提供了Html.fromHtml(String)方法,该方法接收一个字符串并返回一个没有Html标签的新字符串,并相应地进行格式化,因此您只需将sax解析后的字符串提供给该字符串。

相关问题