Grabbing Descendants from an XDocument
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;
}
加载中,请稍侯......
精彩评论