c# - Web 服务的 XML 结果

标签 c# asp.net xml

我想从网络服务中获取 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/

相关文章:

xml - 如何用插件打包我的 joomla 2.5 组件?

c# - WCF TCP比HTTP快多少

c# - PDFsharp MigraDoc 字体在 Azure Web App 中不起作用

c# - 在预定义时间后停止 asp.net c# 中的计时器

c# - Protobuf 消息平台是否独立

c# - Page_Load() 可以异步吗

javascript - 根据JSON信息定位HTML div

c# - 并行任务的最大数量是否有一般规则?

java - 将 Java 类的实例传输到 xml 文件中

java - 理解 xml 模式定位