XML 解析:读取 CDATA [英] XML parsing : Reading CDATA

查看:46
本文介绍了XML 解析:读取 CDATA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<item><title>this is title</title><guid isPermaLink="true">http://www.i.com/video/nokia-lumia-920-deki-pureview_2879.html</guid><link>http://www.i.com/video/nokia-lumia-920-deki-pureview_2879.html</link>
<description><![CDATA[this is the info.]]></description>
<pubDate>Wed, 5 Sep 2012 22:10:00 UT</pubDate>
<media:content type="image/jpg" expression="sample" fileSize="2956" medium="image" url="http://media.chip.com.tr/images/content/video/88/201209060102428081-0.jpg"/>
<enclosure type="image/jpg" url="http://media.chip.com.tr/images/content/video/88/201209060102428081-0.jpg" length="2956"/></item>

我想读取 <"description">

I want read the CDATA in <"description">

我写的

        var x = e.Result;// e is downlaoded xml file

        var videos = XElement.Parse(e.Result);

        var fList = (from haber in videos.Descendants("channel").Elements("item")
                     select new Video
                     {
                         title = haber.Element("title").Value,
                         link = haber.Element("link").Value,
                         //description = ???????
                     }).ToList();

我应该写什么来描述?//编辑答案:同样的方式

what should i write to description ? //EDIT Answer: The same way

但是如果是这样的描述呢?

but if the description like this?

<![CDATA[<p>Zombiler adına ne umduk ne bulduk!</p> <p> </p><p><img style="margin: 5px 0px 5px 5px; border: 1px solid #333333; float: right;" alt="Black_ops" src="http://or.com/images/stories/haber/haberler6/20120918_Castlevania/Black_ops.jpg" height="0" width="0" /><strong>Black Ops 2</strong>'de Zombi modu olabilir haberi çıktığından beri bir ses, bir görüntü beklerken <strong>Call of Duty</strong>'nin resmi <strong>Youtube</strong> sayfasında aşağıdaki video yayınlandı. Açıkçası ne demek istiyorlar anlamak güç. <p><a href="http://or.com/haberler/1-yeni-oyunlar/10624-esi-gorulmemis-call-of-duty-videosu">Devamını oku...</a></p>]]>

推荐答案

您应该能够使用完全相同的代码:

You should be able to use exactly the same code:

description = haber.Element("description").Value

description = (string) haber.Element("description")

LINQ to XML 将负责为您阅读文本.

LINQ to XML will take care of reading the text for you.

这篇关于XML 解析:读取 CDATA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆