c# - Get XML Node Text using LINQ To XML -
Trying to get value for the "title" node from this XML - & gt;
I am using this code:
var d = XDocument.Load ("http://feeds.feedburner.com/dotnetshoutout-published"); Var node = d.oot.Descendants (). Where (x = & gt; x.Name == "title"). FirstOrDefault (); Always gives empty space to make me mad, any help is appreciated.
I think you have an XML namespace on your elements. Therefore, your element name will not be just title , it will be namespace + title . Instead you should check the local name : var node = d. Root.deccundents (). Where (x = & gt; x.LocalName == "title"). FirstOrDefault (); Or, you can see and create namespaces of your elements and use it to bring elements:
XNamespace ns = "Yournamespace"; Var node = d. Route. Desendents (ns + "title"). FirstOver Default (); You can find out more about how to deal with XML namespaces.
Comments
Post a Comment