Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.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 - Fatal编程技术网

C# 使用XPath查询将具有不同命名空间的嵌套节点获取到根目录

C# 使用XPath查询将具有不同命名空间的嵌套节点获取到根目录,c#,.net,xml,xpath,C#,.net,Xml,Xpath,我正在努力从一个XML文档中检索一个节点,该文档的名称空间与文档的其余部分不同 这是XML: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.nominet.or

我正在努力从一个XML文档中检索一个节点,该文档的名称空间与文档的其余部分不同

这是XML:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.nominet.org.uk/epp/xml/epp-1.0 epp-1.0.xsd">
    <response>
        <result code="1000">
            <msg>Command completed successfully</msg>
        </result>
        <resData>
            <domain:infData xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd">
                <domain:name>danielormisher.co.uk</domain:name>
                <domain:roid>50798439-UK</domain:roid>
                <domain:registrant>10DBFAD79B81CCDE</domain:registrant>
            </domain:infData>
        </resData>
        <extension>
            <domain-nom-ext:infData xmlns:domain-nom-ext="http://www.nominet.org.uk/epp/xml/domain-nom-ext-1.0" xsi:schemaLocation="http://www.nominet.org.uk/epp/xml/domain-nom-ext-1.0 domain-nom-ext-1.0.xsd">
                <domain-nom-ext:reg-status>Registered until expiry date.</domain-nom-ext:reg-status>
                <domain-nom-ext:auto-bill>30</domain-nom-ext:auto-bill>
            </domain-nom-ext:infData>
        </extension>
    </response>
</epp>
节点选择得很好。但是,如果我尝试选择节点
,该节点与根节点具有不同的命名空间,如下所示:

namespaces.AddNamespace("domain", "urn:ietf:params:xml:ns:domain-1.0");
var children = doc.SelectSingleNode("/ns:epp/ns:response/ns:resData/domain:infData", namespaces);
namespaces.AddNamespace("domain", "urn:ietf:params:xml:ns:domain-1.0");
namespaces.AddNamespace("domain-nom-ext", "http://www.nominet.org.uk/epp/xml/domain-nom-ext-1.1");
children = doc.SelectSingleNode("/ns:epp/ns:response/ns:extension/domain-nom-ext:infData", namespaces);

我只是得到一个空的响应。有人能指出我做错了什么吗???

您的XML示例有
http://www.nominet.org.uk/epp/xml/domain-nom-ext-1.0
,您的代码使用稍微不同的名称空间
http://www.nominet.org.uk/epp/xml/domain-nom-ext-1.1
(即
1.1
而不是
1.0
。这足以使您的代码不选择任何元素,因为您将需要使用完全相同的命名空间名称。

您的XML示例具有
http://www.nominet.org.uk/epp/xml/domain-nom-ext-1.0
,您的代码使用稍微不同的名称空间
http://www.nominet.org.uk/epp/xml/domain-nom-ext-1.1
(即
1.1
而不是
1.0
。这足以使您的代码不选择任何元素,因为您将需要使用完全相同的命名空间名称。

它看起来像一个输入错误:
http://www.nominet.org.uk/epp/xml/domain-nom-ext-1.1
应该是
http://www.nominet.org.uk/epp/xml/domain-nom-ext-1.0
看起来像是打字错误:http://www.nominet.org.uk/epp/xml/domain-nom-ext-1.1应该是
http://www.nominet.org.uk/epp/xml/domain-nom-ext-1.0