我有以下 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");
这些都不返回任何数据。我一定错过了一些非常简单的东西。