开发者

Grabbing Descendants from an XDocument

开发者 https://www.devze.com 2023-01-24 04:59 出处:网络
I am trying to grab all the <entry> tags from this site. It will load just fine into an XDocument but I cannot seem to grab any of the <entry> elements. Here is the code I have:

I am trying to grab all the <entry> tags from this site. It will load just fine into an XDocument but I cannot seem to grab any of the <entry> elements. Here is the code I have:

XDocument netflixPage = new XDocument();
netflixPage = XDocument.Load("http://odata.netflix.com/Catalog/Titles");

foreach (XElement xe in netflixPage.Descendants("e开发者_开发问答ntry").ToList())
{
    string movieInfo = xe.Value;
}


Your code attempts to retrieve entry elements in the   namespace, but the document contains entry elements in the http://www.w3.org/2005/Atom namespace:

XNamespace atom = "http://www.w3.org/2005/Atom";

XDocument doc = XDocument.Load("http://odata.netflix.com/Catalog/Titles");

foreach (XElement xe in doc.Descendants(atom + "entry"))
{
    string movieInfo = (string)xe;
}
0

精彩评论

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