我正在通过SAX解析器进行RSS解析,我得到了这种格式的描述:
<description><![CDATA[<div><b>Start Time:</b> 12/19/2010 6:30 PM</div>
<div><b>End Time:</b> 12/19/2010 10:00 PM</div>
<div><b>Description:</b> Break Guinness World Records of arda</div>
<div><b>Type of Event:</b> <a onclick="OpenPopUpPage('http://www.example.com/_layouts/listform.aspx?PageType=4&ListId={5368B20F-2E1F-4984-9308-3E46442B2336}&ID=79&RootFolder=*', RefreshPage); return false;" href="http://www.example.com/_layouts/listform.aspx?PageType=4&ListId={5368B20F-2E1F-4984-9308-3E46442B2336}&ID=79&RootFolder=*">Aspire closed stadium</a></div>
<div><b>Localization Data:</b> <data><item field="Title" lang="ar-SA"> Break record </item><item field="Description" lang="ar-SA">&lt;P align=right&gt;Break record &amp;nbsp; 9/12/2010 Break record " National " Men Poetry Activities . &lt;/P&gt;</item></data></div>
<div><b>LocationInInteractiveMap:</b> Don't Show</div>
<div><b>Latitude:</b> 25.266024</div>
<div><b>Longitude:</b> 51.443814</div>
<div><b>EventLogo:</b> <img alt="" src="/SiteCollectionImages/Event%20Images/Default.png" style="BORDER: 0px solid; "></div>
]]></description>
那么我如何从这个HTML代码中获取标记值?
答案 0 :(得分:1)
您想要显示此描述值的位置?如果您想在 TextView
中显示,请写:
TextView foo = (TextView)findViewById(R.id.foo);
foo.setText(Html.fromHtml(description));
或者
您可以在 WebView
:
webview.loadData(description, "text/html", null);
答案 1 :(得分:1)
试试这个,
Html.fromHtml(String source)
Returns displayable styled text from the provided HTML string.
并且
Html.fromHtml (String source, Html.ImageGetter imageGetter, Html.TagHandler tagHandler)
自:API Level 1
从提供的HTML字符串返回可显示的样式文本。任何 HTML中的标签将使用指定的ImageGetter来请求 图像的表示(如果你不想要这个,则使用null)和 指定TagHandler来处理未知标记(如果不这样做,则指定null) 想要这个。)
Be sure : Have your source markup be valid HTML?