Trying to get the value for the "title" node from this XML -> http://feeds.feedburner.com/dotnetshoutout-published
I am using this code:
var d = XDocument.Load("http://feeds.feedburner.com/dotnetshoutout-published");
var node = d.Root.Descendants().Where(x => x.Name == "title").FirstOrDefault();
Always returns null. Making me crazy, any assistance is appreciated.
I guess you have an Xml Namespace on your elements.If so, your element name won't be just title
, it will be namespace + title
.Instead you should check the LocalName
:
var node = d.Root.Descendants().Where(x => x.LocalName == "title").FirstOrDefault();
Or, you can look at the namespace of your elements and create an XNamespace
and use it to fetch elements:
XNamespace ns = "yournamespace";
var node = d.Root.Descendants(ns + "title").FirstOrDefault();
You can read the documentation to find more info about how to deal with xml namespaces.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments