XmlDocument解析Soap格式文件案例:

 private static string Analysis(string strResult)
 {
   var doc = new System.Xml.XmlDocument();
    //加载soap文件,文件格式如:strResult
    doc.LoadXml(strResult);
    string q1 = doc.DocumentElement["soap:Body"]["SendSmsResponse"].InnerXml;//该处是否必须,请各位大侠自己测试
    doc.LoadXml(q1);
    //xml 命名空间
    XmlNamespaceManager xmlns = new XmlNamespaceManager(doc.NameTable);
    //xml 命名空间缩写
    xmlns.AddNamespace("H", "http://www.yysms.com/");
   //获取xml文件<StatusCode></StatusCode>节点下的文本值
   var s = doc.SelectSingleNode("/H:SendSmsResult/H:StatusCode", xmlns).InnerText;
   return s
}
strResult:Soap文件
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema">
     <soap:Body>
    <SendSmsResponse xmlns="http://www.yysms.com/">
       <SendSmsResult>
         <PayType>0</PayType>
         <StatusCode>OK</StatusCode>
         <Description>操作成</Description>
         <MsgId>1611084043570792</MsgId>
         <SuccessCounts>1</SuccessCounts>
         <BillingCount>1</BillingCount>
         <Amount>909</Amount>
         <Balance>0</Balance>
         <BillingAmount>0</BillingAmount>
         <Errors />
           </SendSmsResult>
    </SendSmsResponse>
    </soap:Body>
</soap:Envelope>
原文地址:https://www.cnblogs.com/rengke2002/p/6046126.html