<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;