如何从Android中的HTMl代码获取Tag值?

发布于 2024-12-11 09:54:19 字数 1712 浏览 2 评论 0原文

我正在通过 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> &lt;data&gt;&lt;item field=&quot;Title&quot; lang=&quot;ar-SA&quot;&gt; Break record &lt;/item&gt;&lt;item field=&quot;Description&quot; lang=&quot;ar-SA&quot;&gt;&amp;lt;P align=right&amp;gt;Break record &amp;amp;nbsp;  9/12/2010 Break record    &quot; National  &quot;  Men Poetry Activities . &amp;lt;/P&amp;gt;&lt;/item&gt;&lt;/data&gt;</div>

<div><b>LocationInInteractiveMap:</b> Don&#39;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 代码中获取标签值呢?

I am doing RSS parsing by SAX parser and i am getting Description in this format :

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

so how i am getting tag value from this html code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

披肩女神 2024-12-18 09:54:19

试试这个,

 Html.fromHtml(String source)
 Returns displayable styled text from the provided HTML string.

Html.fromHtml  (String source, Html.ImageGetter imageGetter, Html.TagHandler tagHandler)

API 级别 1 开始

从提供的 HTML 字符串返回可显示样式的文本。任何
HTML 中的标签将使用指定的 ImageGetter 来请求
图像的表示(如果你不想要这个,请使用 null )和
指定 TagHandler 来处理未知标签(如果不指定则指定 null
想要这个)。

Be sure : Have your source markup be valid HTML? 

Try this,

 Html.fromHtml(String source)
 Returns displayable styled text from the provided HTML string.

And

Html.fromHtml  (String source, Html.ImageGetter imageGetter, Html.TagHandler tagHandler)

Since: API Level 1

Returns displayable styled text from the provided HTML string. Any
tags in the HTML will use the specified ImageGetter to request a
representation of the image (use null if you don't want this) and the
specified TagHandler to handle unknown tags (specify null if you don't
want this).

Be sure : Have your source markup be valid HTML? 
甜心小果奶 2024-12-18 09:54:19

您想在哪里显示此描述值?如果您想在 TextView 中显示它,请编写:

TextView foo = (TextView)findViewById(R.id.foo);
foo.setText(Html.fromHtml(description));

或者

您可以在 WebView 中加载描述字符串值>:

 webview.loadData(description, "text/html", null);

Where you want to display this Description value? If you want to display it inside the TextView then write:

TextView foo = (TextView)findViewById(R.id.foo);
foo.setText(Html.fromHtml(description));

Or

You can load the Description string value inside the WebView:

 webview.loadData(description, "text/html", null);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文