c# 對SOAP返回XML字符串的解析方法


<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Header/>
  <SOAP:Body>
    <ns0:MT_COMMON xmlns:ns0="http://www.db.com">
      <KEY>關鍵標示</KEY>
      <DATAJSON>數組內容</DATAJSON>
    </ns0:MT_COMMON>
  </SOAP:Body>
</SOAP:Envelope>

針對上面格式的XML字符串,獲取出來 數組內容或關鍵標示

解析代碼:

 try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(strxml);//Load加載XML文件,LoadXML加載XML字符串
                XmlElement root = xmlDoc.DocumentElement;
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);

                XmlNode xnode = root.FirstChild;
                nsmgr.AddNamespace("ns0", "http://www.db.com");
                value = xnode.SelectSingleNode("//ns0:MT_COMMON", nsmgr)
                    .SelectSingleNode("DATAJSON").InnerText;
                
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return value;
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM