2013-03-27 73 views
1

自動生成一些文檔(並學習xpath)我打算從WSDL文件中獲取所有操作的列表。使用xpath從wsdl文件中選擇所有操作

我迄今爲止嘗試是:

 doc = new XmlDocument(); 
     doc.Load(@"C:\temp\tempuri.org.wsdl"); 
     var list = doc.SelectNodes("wsdl:definitions/wsdl:portType/wsdl:operation"); 

這給我的錯誤:

Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.

任何人都可以解釋爲什麼我收到此錯誤,以及如何解決它?

回答

1

我建議考慮看看這個答案:C# XPath help - Expression not working

您需要在開始查詢前註冊的命名空間wsdl

例如爲:

XPathDocument xDoc = new XPathDocument(@"C:\temp\tempuri.org.wsdl"); 
XPathNavigator xNav = xDoc.CreateNavigator(); 
XmlNamespaceManager mngr = new XmlNamespaceManager(xNav.NameTable); 
mngr.AddNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/"); // this namespace may need to be different - I don't know what your wsdl file looks like 
XPathNodeIterator xIter = xNav.Select("wsdl:definitions/wsdl:portType/wsdl:operation",mngr); 

或者您可以使用LINQ到XML - 看到喬恩斯基特這樣的回答:Namespace Manager or XsltContext needed

但是你說你想學習的XPath,所以我想這是無關緊要的。