试图获得"标题"的价值来自此XML的节点 - > http://feeds.feedburner.com/dotnetshoutout-published
我正在使用此代码:
var d = XDocument.Load("http://feeds.feedburner.com/dotnetshoutout-published");
var node = d.Root.Descendants().Where(x => x.Name == "title").FirstOrDefault();
始终返回null。让我发疯,任何帮助都表示赞赏。
答案 0 :(得分:1)
我猜您的元素上有一个Xml命名空间。如果是这样,您的元素名称将不仅仅是title
,而是namespace + title
。相反,您应该检查LocalName
:
var node = d.Root.Descendants().Where(x => x.LocalName == "title").FirstOrDefault();
或者,您可以查看元素的命名空间并创建XNamespace
并使用它来获取元素:
XNamespace ns = "yournamespace";
var node = d.Root.Descendants(ns + "title").FirstOrDefault();
您可以阅读documentation以查找有关如何处理xml命名空间的更多信息。