Get XML Node Text using LINQ To XML

CmdrTallen

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.

Selman Genç

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get XML element value using XML to Linq

From Dev

Get value of an Xml attribute using Linq to Xml

From Dev

Get attribute value of parent node by Linq to XML

From Dev

Insert XComment before node using Linq to XML

From Dev

Get the text only part of an xml node

From Dev

Get main element attributes of XML using LINQ

From Dev

Get custom attribute value using LINQ to XML

From Dev

Returning XML node text as an array using find()

From Dev

Finding text in a XML Node using Jquery Mobile

From Dev

Replacting XML node text using PowerShell

From Dev

Generate xml using LINQ to XML

From Dev

Generate xml using LINQ to XML

From Dev

Parse XML using LINQ to XML?

From Dev

get all parents of xml node using python

From Dev

Get Node value from a XML using xmllint

From Dev

Get node value in XML using jQuery

From Dev

Get Node value from a XML using xmllint

From Dev

get all parents of xml node using python

From Dev

get xml node value using c#

From Dev

How to get an XML node values using Java?

From Dev

Parsing XML using lxml, unable to get text when there is another child node

From Dev

How to Select an XML Node with a Namespace in LINQ to XML

From Dev

Attribute value in root node of xml Linq to XML

From Dev

How to choose an XML Node? (Using LINQ, XPath, anything is fine)

From Dev

How to check if a particular XML node exists by using LINQ

From Dev

Adding child nodes to a node in XML using Linq To excel

From Dev

How to choose an XML Node? (Using LINQ, XPath, anything is fine)

From Dev

Linq to XML - parse a node into dictionary

From Dev

how to update xml node with linq