Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 重复:具有默认命名空间的XPath表达式_C#_.net_Xml_Xpath_Odata - Fatal编程技术网

C# 重复:具有默认命名空间的XPath表达式

C# 重复:具有默认命名空间的XPath表达式,c#,.net,xml,xpath,odata,C#,.net,Xml,Xpath,Odata,我目前正在编写一个C类,它允许我从OData提要构造实体。 别问为什么,我现在就需要它: XML的片段如下所示: <?xml version="1.0" encoding="utf-8" standalone="yes"?> <entry xml:base="http://demo.tenforce.acc/Api.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="htt

我目前正在编写一个C类,它允许我从OData提要构造实体。 别问为什么,我现在就需要它:

XML的片段如下所示:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<entry xml:base="http://demo.tenforce.acc/Api.svc/" 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">
  <id>http://demo.tenforce.acc/Api.svc/Items(387)</id>
  <title type="text"></title>
  <updated>2011-09-22T07:35:54Z</updated>
  <author>
    <name />
  </author>
  <link rel="edit" title="Item" href="Items(387)" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Children" type="application/atom+xml;type=feed" title="Children" href="Items(387)/Children" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Parent" type="application/atom+xml;type=entry" title="Parent" href="Items(387)/Parent" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Attachments" type="application/atom+xml;type=feed" title="Attachments" href="Items(387)/Attachments" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Predecessors" type="application/atom+xml;type=feed" title="Predecessors" href="Items(387)/Predecessors" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Successors" type="application/atom+xml;type=feed" title="Successors" href="Items(387)/Successors" />
  <category term="TenForce.Execution.Api2.Objects.Item" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
  <content type="application/xml">
    <m:properties>
      <d:Id m:type="Edm.Int32">387</d:Id>
    </m:properties>
  </content>
</entry>
我创建了一个代码片段,将整个xml字符串加载到一个XmlDocument中,并生成一个XmlNamespaceManager来访问各种名称空间

我试图从XML中选择元素,但似乎无法获得正确的Xpath表达式。我尝试了以下方法:

//条目/类别 后代::xmlns:cateogray //d:类别 //m:类别 //类别 //xml:类别
但是没有一个节点被选中。

哦,没关系,我已经找到了解决方案。 我必须为atom元素添加名称空间

var manager = new XmlNamespaceManager(_mDocument.NameTable);
manager.AddNamespace("d", "http://schemas.microsoft.com/ado/2007/08/dataservices");
manager.AddNamespace("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
manager.AddNamespace("atom", "http://www.w3.org/2005/Atom");
这允许我使用//atom:category

另一个副本的可能副本来选择元素