【问题标题】:How to parse html nested tag using SAX parser of android如何使用android的SAX解析器解析html嵌套标签
【发布时间】:2012-05-26 22:13:32
【问题描述】:

我的 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>

我需要删除“&lt;div&gt;&lt;b&gt;” n 只想显示内容。 我应该为此做些什么。? 请帮我。 提前致谢。

【问题讨论】:

  • 看看这对你有没有帮助:stackoverflow.com/questions/9244345/…
  • 我已经尝试了上面的链接,但它只给了我这个输出:
    位置:PUMBA礼堂 - 浦那大学
    我想要的输出是: PUMBA 礼堂 - 浦那大学 开始时间:2012 年 5 月 15 日上午 11:00 结束时间:2012 年 5 月 15 日下午 2:00 描述:2012 年 BC 乔希将军纪念讲座 - 21 世纪战争的观点 - Lt . AK Singh 将军 附件:uopnews.unipune.ac.in/Lists/Calendar/Attachments/14/…。有没有办法获得这种类型的输出?

标签: android xml-parsing sax


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-22
    • 2017-05-04
    • 2011-04-30
    • 1970-01-01
    • 2013-02-08
    • 2013-01-08
    相关资源
    最近更新 更多