2015-04-23 84 views
4

我想從web服務獲取XML結果。我試過下面的代碼來自web服務的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; 

但我無法得到結果,它顯示錯誤名稱空間前綴'soapenv'未定義。任何幫助對我都有幫助。

+1

你只有註冊'xsl'前綴'nsmgr',這就是爲什麼'soapenv'認爲「沒有定義」 ......還我不t認爲你需要那些'-'在那個特定的xpath – har07

+0

我還必須註冊soapenv? –

+0

是的。您將在xpath – har07

回答

2

這是解決你的問題註冊信息前綴的信息。例如,您爲「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/"); 
+0

正在註冊與此網址http://www.w3.org/1999/XSL/Transform? –

+0

不。這是** xsl **前綴。對於「soapenv」,應該在xml文件中提及。請檢查您的XML文件的開始。它應該在那裏。 – Keval

+0

是的,這是來自瀏覽器的結果 xxxx並且我必須檢索密碼內文 –