1

I am trying to get some data from this WSDL file(xml format) "http://pastebin.com/gF7aHwa3", for example, the value of wsdl:service name, which is CinemaData. Not getting any value with this code:

 static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(@"C:\wsdl\0_Argentina_CinemaData.wsdl");

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
            //nsmgr.AddNamespace("soap", "http://schemas.xmlsoap.org/wsdl/soap");
            //nsmgr.AddNamespace("tm", "http://microsoft.com/wsdl/mime/textMatching");
            //nsmgr.AddNamespace("soapenc", "http://schemas.xmlsoap.org/soap/encoding");
            //nsmgr.AddNamespace("mime", "http://schemas.xmlsoap.org/wsdl/mime");
            //nsmgr.AddNamespace("tns", "http://www.e-wavegroup.com");
            //nsmgr.AddNamespace("s", "http://www.w3.org/2001/XMLSchema");
            //nsmgr.AddNamespace("soap12", "http://schemas.xmlsoap.org/wsdl/soap12");
            //nsmgr.AddNamespace("http", "http://schemas.xmlsoap.org/wsdl/http");
            //nsmgr.AddNamespace(String.Empty, "http://www.e-wavegroup.com");
            nsmgr.AddNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl");


            XmlNodeList SNameNodes = doc.DocumentElement.SelectNodes("//wsdl:definition/wsdl:service", nsmgr);

            List<serviceName> snList = new List<serviceName>();

            foreach (XmlNode node in SNameNodes)
            {
                System.Console.WriteLine("The service name is " + node.Attributes["name"].Value);                                      
            }
        }
Mic O
  • 11
  • 1

1 Answers1

0

There are a couple of issues :)

  1. The namespace is http://schemas.xmlsoap.org/wsdl/ not http://schemas.xmlsoap.org/wsdl - the trailing slash makes them entirely different
  2. The root node is wsdl:definitions not wsdl:definition

So:

var nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/");
var SNameNodes = doc.SelectNodes("/wsdl:definitions/wsdl:service", nsmgr);
foreach (XmlNode node in SNameNodes)
{
    System.Console.WriteLine("The service name is " + node.Attributes["name"].Value);
}

You also can access SelectNodes directly off Document, and given that wsdl:definitions is the root node, you don't need the double-slash.

A last point - you might want to look at migrating to Linq to Sql - you still have full XPath parsing capabilities, plus it has many other benefits.

Community
  • 1
  • 1
StuartLC
  • 104,537
  • 17
  • 209
  • 285