C# I';当导航到soap消息中的元素时,我遇到xpath错误
编程语言-c# 下面提到的错误正在显示C# I';当导航到soap消息中的元素时,我遇到xpath错误,c#,xpath,soap,C#,Xpath,Soap,编程语言-c# 下面提到的错误正在显示 Unhandled Exception: System.Xml.XPath.XPathException: Namespace Manager or XsltC ontext needed. This query has a prefix, variable, or user-defined function. 这是我用来返回内部文本的代码 XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(@"C
Unhandled Exception: System.Xml.XPath.XPathException: Namespace Manager or XsltC
ontext needed. This query has a prefix, variable, or user-defined function.
这是我用来返回内部文本的代码
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(@"C:\test\myfile.xml");
var nsmgr = new XmlNamespaceManager(xmldoc.NameTable);
nsmgr.AddNamespace("env", "http://schemas.xmlsoap.org/soap/envelope/");
nsmgr.AddNamespace("ns1", "http://sse/ECOM:1.0:schema:messages");
nsmgr.AddNamespace("wsa", "http://www.w3.org/2005/08/addressing");
XmlNode node = xmldoc.SelectsingleNode("/*/env:Body/env:response/env:customerAccountsGrp[1]/env:customerAccountID");
Console.WriteLine(xmldoc.SelectSingleNode("/*/env:Body/env:response/env:customerAccountsGrp[1]/env:customerAccountID").InnerText);
这是soap消息
<env:Envelope
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsa="http://www.w3.org/2005/08/addressing">
<env:Header>
<wsa:MessageID>urn:5C4DCC70E6F411E69F7EF5AAD683B4B3</wsa:MessageID>
<wsa:ReplyTo>
<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
</wsa:ReplyTo><wsa:FaultTo> <wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
</wsa:FaultTo>
</env:Header>
<env:Body>
<response
xmlns:ns0="urn:sse:ECOM:1.0:schema:messages"
xmlns="urn:sse:ECOM:1.0:schema:messages">
<ns0:customerAccountsGrp>
<ns0:customerAccountID>1212121212</ns0:customerAccountID>
<ns0:customerAccountStatus>AC</ns0:customerAccountStatus>
<ns0:serviceType>AB</ns0:serviceType>
<ns0:brandCode>XXX </ns0:brandCode>
<ns0:affinityType> </ns0:affinityType>
<ns0:paymentType>VV</ns0:paymentType>
</ns0:customerAccountsGrp><ns0:customerAccountsGrp>
<ns0:customerAccountID>4545454545445</ns0:customerAccountID>
<ns0:customerAccountStatus>BC</ns0:customerAccountStatus>
<ns0:serviceType>FH</ns0:serviceType>
<ns0:brandCode>SE</ns0:brandCode>
<ns0:affinityType></ns0:affinityType>
<ns0:paymentType>NM</ns0:paymentType>
</ns0:customerAccountsGrp>
urn:5C4DC70E6F41E69F7EF5AAD683B3
http://www.w3.org/2005/08/addressing/anonymous
http://www.w3.org/2005/08/addressing/anonymous
1212121212
自动控制
AB
XXX
VV
4545454545445
卑诗省
跳频
东南方
纳米
有人能帮我解决这个问题吗?致以最诚挚的问候。您尚未声明名称空间
xmlns:ns0=“urn:sse:ECOM:1.0:schema:messages”xmlns=“urn:sse:ECOM:1.0:schema:messages”>
您已将其部分转换为URI。它们应该完全像在SOAP信封中一样出现。我现在已经这样做了,但仍然得到相同的错误。。。。。。nsmgr.AddNamespace(“env”,);nsmgr.AddNamespace(“ns0”,“xmlns:ns0=urn:sse:ECOM:1.0:schema:messages”);nsmgr.AddNamespace(“ns1”,“xmlns=urn:sse:ECOM:1.0:schema:messages”);nsmgr.AddNamespace(“wsa”);XmlNode node=xmldoc.SelectSingleNode(/env:Envelope/env:Body/env:response/ns0:customerAccountsGrp[1]/ns0:customerAccountID”);感谢您现在就收到了…workingnsmgr.AddNamespace(“ns0”,“urn:sse:ECOM:1.0:schema:messages”);nsmgr.AddNamespace(“ns1”,urn:sse:ECOM:1.0:schema:messages”);您尚未声明名称空间xmlns:ns0=“urn:sse:ECOM:1.0:schema:messages”xmlns=“urn:sse:ECOM:1.0:schema:messages”>
您已将它们部分转换为URI。它们应该完全像在SOAP信封中一样出现。我现在已经这样做了,但仍然得到相同的错误。。。。。。nsmgr.AddNamespace(“env”,);nsmgr.AddNamespace(“ns0”,“xmlns:ns0=urn:sse:ECOM:1.0:schema:messages”);nsmgr.AddNamespace(“ns1”,“xmlns=urn:sse:ECOM:1.0:schema:messages”);nsmgr.AddNamespace(“wsa”);XmlNode node=xmldoc.SelectSingleNode(/env:Envelope/env:Body/env:response/ns0:customerAccountsGrp[1]/ns0:customerAccountID”);感谢您现在就收到了…workingnsmgr.AddNamespace(“ns0”,“urn:sse:ECOM:1.0:schema:messages”);nsmgr.AddNamespace(“ns1”,urn:sse:ECOM:1.0:schema:messages”);