开发者

How to parse this XML using linq to xml?

i am trying to parse following xml but no sucess any one guide me what mistake am i doing here

 string feedURL = "http://www.bbc.co.uk/arabic/index.xml";
 XDocument feedSource;
        feedSource = XDocument.Load(feedURL);

 var another = (from myFeed in feedSource.Descendants("entry")
                         select new
                         {
     开发者_C百科                        feedTitle = myFeed.Element("title").Value,
                             //feedDescription = myFeed.Element("description").Value,
                             //feedLink = myFeed.Element("link").Value,
                             feedpubDate = myFeed.Element("published") != null ? myFeed.Element("published").Value : null
                             //feedcategory = myFeed.Element("category") != null ? myFeed.Element("category").Value : null,
                             //feedItems = myFeed.Descendants("entry")
                         }
        );


            if (another != null && another.Count() > 0)
            {


            }
            else
            {
                Response.Write("No Record Found");
            }

it is showing me no record found.

any help would be appreciated.


This worked in LINQPad:

XNamespace xns = "http://www.w3.org/2005/Atom";
var xdoc = XDocument.Load("http://www.bbc.co.uk/arabic/index.xml");
xdoc.Element(xns + "feed").Elements(xns + "entry");

Problem was the lacking namespace.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜