Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
991 views
in Technique[技术] by (71.8m points)

c# - XML parsing : Reading 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>

I want read the CDATA in <"description">

I wrote this

        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>]]>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should be able to use exactly the same code:

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

Or

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...