2012-09-19 112 views
4
<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> 

我想在< “说明” 读CDATA>XML解析:阅读CDATA

我写这

 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(); 

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

但是如果描述是这样的?

<![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>]]> 

回答

9

你应该能完全一样的代码中使用:

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

或者

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

的LINQ to XML将采取的阅读文本您的照顾。

+0

我编辑了我的问题,你能帮助我吗? –

+2

@ user1248643:不是真的,因为如果你尝试我所说的话,你还没有说过会出现什么问题。我期望从元素中提取HTML就好了。如果你想从HTML中提取*文本,那么这是一个完全独立的问题,与CDATA相关性不大。 –

+0

我明白谢谢你 –

1

要读取CDATA块,只需使用相同的方法;你想要的是清除它的HTML,然后检查this answer