我想从网络服务中获取 XML 结果。我试过下面的代码
XmlDocument doc = new XmlDocument();
string xml = "http://www.examplexml.com/2323223";
doc.Load(xml);
var nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
XmlNode node = doc.SelectSingleNode("/-soapenv:Envelope/-soapenv:Body/
-GetPasswordResponse/Password", nsmgr);
string password = node.InnerText;
但我无法得到结果,它显示错误 Namespace prefix 'soapenv' is not defined。任何帮助都会对我有所帮助。
最佳答案
这解决了您注册前缀信息路径的问题。例如,就像您对“xsl”所做的那样。
nsmgr.AddNamespace("soapenv", "Here is the URL of mention at starting point in your xml file");
所以它应该是这样的,
nsmgr.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
关于c# - Web 服务的 XML 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29818453/