【发布时间】:2011-12-29 11:18:03
【问题描述】:
我有xml代码:
<feed xml:base="https://test.net/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
<title type="text">CustomTable5</title>
<id>https://eqmetest.table.core.windows.net/CustomTable5</id>
<updated>2011-11-15T11:36:32Z</updated>
<link rel="self" title="CustomTable5" href="CustomTable5" />
<entry m:etag="W/"datetime'2011-11-05T08%3A29%3A45.8347866Z'"">
<id>https://eqmetest.table.core.windows.net/CustomTable5(PartitionKey='',RowKey='1')</id>
<title type="text"></title>
<updated>2011-11-15T11:36:32Z</updated>
<author>
<name />
</author>
<link rel="edit" title="CustomTable5" href="CustomTable5(PartitionKey='',RowKey='1')" />
<category term="eqmetest.CustomTable5" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:PartitionKey></d:PartitionKey>
<d:RowKey>1</d:RowKey>
<d:Timestamp m:type="Edm.DateTime">2011-11-05T08:29:45.8347866Z</d:Timestamp>
<d:LastID m:type="Edm.Int32">54</d:LastID>
</m:properties>
</content>
</entry>
</feed>
我需要一个元素名称列表(在我的情况下应该是:PartitionKey,RowKey,Timestamp,LastID),如果有更多标签,我的列表应该来自 LastID.Value==一些身份
刚开始我已经写了这个:
XmlNamespaceManager xs = new XmlNamespaceManager(new NameTable());
xs.AddNamespace("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
xs.AddNamespace("a", "http://www.w3.org/2005/Atom");
xs.AddNamespace("d", "http://schemas.microsoft.com/ado/2007/08/dataservices");
var propertiesElement = document.XPathSelectElements("/a:feed/a:entry/a:content/m:properties", xs);
但我不知道如何结束)
【问题讨论】:
-
您确定要在这里使用 XPath 吗?就我个人而言,我只会使用 LINQ to XML 方法,尤其是在涉及名称空间的情况下。
-
如果您可以帮助使用 LINQ to XML 方法 - 没关系)
标签: c# xml linq-to-xml xml-parsing