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

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -