dazzling kumar
dazzling kumar

Reputation: 604

XML result from web service

I want to get a XML result from the webservice. I have tried the below code

    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;

But I couldn't get the result, It shows the error Namespace prefix 'soapenv' is not defined. Any help would be helpful for me.

Upvotes: 4

Views: 210

Answers (1)

Keval Gangani
Keval Gangani

Reputation: 1328

This is solve your problem to register infopath of prefixes. For example as you did for "xsl".

nsmgr.AddNamespace("soapenv", "Here is the URL of mention at starting point in your xml file");

So it should be look like this,

nsmgr.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");

Upvotes: 2

Related Questions