0
我有下面的XML:获取元素集合从XML
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<author>
<name />
</author>
<title>Publishing Point Collection</title>
<updated>2013-01-14T15:58:44.589Z</updated>
<entry>
<id>http://example.com:80/test filename.isml/settings</id>
<title>Test Title</title>
<updated>2013-01-14T15:47:15Z</updated>
<link href="http://example.com:80/test filename.isml/settings" rel="related" type="application/atom+xml" title="Settings" />
<link href="http://example.com:80/test filename.isml/state" rel="related" type="application/atom+xml" title="State" />
<link href="http://example.com:80/test filename.isml/statistics" rel="related" type="application/atom+xml" title="Statistics" />
</entry>
</feed>
我做加载文档:
//xmlContent is the XML shown above.
XDocument publishingDocument = XDocument.Parse(xmlContent);
我试图让所有的链接元素(特别是href属性,但是,现在只是元素)。但是,任何时候我指定一个XName我永远不会得到任何结果。我试过了:
var data = publishingDocument.Elements("entry");
var data = publishingDocument.Elements("link").Attributes("href");
var data = publishingDocument.Root.Elements("entry");
这些都没有返回任何数据。我必须错过一些非常简单的事情。
尝试VAR数据= publishingDocument.Descendants( “链接”)。元素(),我相信,只适用于根级元素。 – Pete
@Pete - 试过了。我没有得到任何结果。 –