C# 解析SOAP返回

C# 解析SOAP返回,c#,xml,soap,C#,Xml,Soap,好的,我知道有很多帖子,也读过很多,但是我的代码中缺少了一些东西,我就是看不到什么 作为一个背景故事,我正在尝试解析一个来自Cisco电话系统的soap返回,我用它处理他们的旧版本,但现在我无法获取它来提取我需要的数据 这是我的密码: String xmlText = File.ReadAllText(@"c:\temp\IPAddress.xml"); XmlDocument doc = new XmlDocument(); XmlNamespaceManager n

好的,我知道有很多帖子,也读过很多,但是我的代码中缺少了一些东西,我就是看不到什么

作为一个背景故事,我正在尝试解析一个来自Cisco电话系统的soap返回,我用它处理他们的旧版本,但现在我无法获取它来提取我需要的数据

这是我的密码:

    String xmlText = File.ReadAllText(@"c:\temp\IPAddress.xml");

    XmlDocument doc = new XmlDocument();
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);

    nsmgr.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
    nsmgr.AddNamespace("ns1", "http://schemas.cisco.com/ast/soap/");
    doc.LoadXml(xmlText);

    XmlNodeList items = doc.SelectNodes("/soapenv:Envelope/soapenv:Body/ns1:selectCmDeviceResponse/ns1:selectCmDeviceReturn/ns1:SelectCmDeviceResult/ns1:CmNodes/ns1:item/ns1:CmDevices/ns1:item", nsmgr);
    Console.WriteLine(doc.InnerText.ToString());
    foreach (XmlNode item in items)
    {
        string Name = GetNodeValue(item, "Name");
        string Description = GetNodeValue(item, "ns1:Description");
        string IpAddress = GetNodeValue(item, "ns1:IpAddress/ns1:item/ns1:IP");
        string DirNumber = GetNodeValue(item, "ns1:DirNumber");
        string Class = GetNodeValue(item, "ns1:DeviceClass");
        string Model = GetNodeValue(item, "ns1:Model");
        string Product = GetNodeValue(item, "ns1:Product");

        UpdateInfo(Name, IpAddress);
    }
}


Here is a snip of the XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <ns1:selectCmDeviceResponse xmlns:ns1="http://schemas.cisco.com/ast/soap">
         <ns1:selectCmDeviceReturn>
            <ns1:SelectCmDeviceResult>
               <ns1:TotalDevicesFound>4</ns1:TotalDevicesFound>
               <ns1:CmNodes>
                  <ns1:item>
                     <ns1:ReturnCode>Ok</ns1:ReturnCode>
                     <ns1:Name>10.0.5.125</ns1:Name>
                     <ns1:NoChange>false</ns1:NoChange>
                     <ns1:CmDevices>
                        <ns1:item>
                           <ns1:Name>SEP1CE6C7729944</ns1:Name>
                           <ns1:DirNumber>4402-UnRegistered</ns1:DirNumber>
                           <ns1:DeviceClass>Phone</ns1:DeviceClass>
                           <ns1:Model>435</ns1:Model>
                           <ns1:Product>334</ns1:Product>
                           <ns1:BoxProduct>0</ns1:BoxProduct>
                           <ns1:Httpd>Yes</ns1:Httpd>
                           <ns1:RegistrationAttempts>0</ns1:RegistrationAttempts>
                           <ns1:IsCtiControllable>true</ns1:IsCtiControllable>
                           <ns1:LoginUserId>earlene.gonzalez</ns1:LoginUserId>
                           <ns1:Status>UnRegistered</ns1:Status>
                           <ns1:StatusReason>8</ns1:StatusReason>
                           <ns1:PerfMonObject>2</ns1:PerfMonObject>
                           <ns1:DChannel>0</ns1:DChannel>
                           <ns1:Description>105_GRN_LO-PH</ns1:Description>
                           <ns1:H323Trunk>
                              <ns1:ConfigName xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:TechPrefix xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:Zone xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer1 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer2 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer3 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:AltGkList xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:ActiveGk xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:CallSignalAddr xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RasAddr xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           </ns1:H323Trunk>
                           <ns1:TimeStamp>1494272299</ns1:TimeStamp>
                           <ns1:Protocol>SCCP</ns1:Protocol>
                           <ns1:NumOfLines>1</ns1:NumOfLines>
                           <ns1:LinesStatus>
                              <ns1:item>
                                 <ns1:DirectoryNumber>4402</ns1:DirectoryNumber>
                                 <ns1:Status>UnRegistered</ns1:Status>
                              </ns1:item>
                           </ns1:LinesStatus>
                           <ns1:ActiveLoadID>SCCP45.9-4-2SR2-2S</ns1:ActiveLoadID>
                           <ns1:InactiveLoadID xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:DownloadStatus>Unknown</ns1:DownloadStatus>
                           <ns1:DownloadFailureReason xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:DownloadServer xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:IPAddress>
                              <ns1:item>
                                 <ns1:IP>10.105.2.55</ns1:IP>
                                 <ns1:IPAddrType>ipv4</ns1:IPAddrType>
                                 <ns1:Attribute>AdministrativeAndSignaling</ns1:Attribute>
                              </ns1:item>
                           </ns1:IPAddress>
                        </ns1:item>
                        <ns1:item>
                           <ns1:Name>SEP1CE6C772F3FB</ns1:Name>
                           <ns1:DirNumber xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:DeviceClass>Phone</ns1:DeviceClass>
                           <ns1:Model>435</ns1:Model>
                           <ns1:Product>334</ns1:Product>
                           <ns1:BoxProduct>0</ns1:BoxProduct>
                           <ns1:Httpd>Yes</ns1:Httpd>
                           <ns1:RegistrationAttempts>1</ns1:RegistrationAttempts>
                           <ns1:IsCtiControllable>true</ns1:IsCtiControllable>
                           <ns1:LoginUserId xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:Status>Rejected</ns1:Status>
                           <ns1:StatusReason>27</ns1:StatusReason>
                           <ns1:PerfMonObject>0</ns1:PerfMonObject>
                           <ns1:DChannel>0</ns1:DChannel>
                           <ns1:Description xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:H323Trunk>
                              <ns1:ConfigName xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:TechPrefix xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:Zone xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer1 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer2 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer3 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:AltGkList xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:ActiveGk xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:CallSignalAddr xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RasAddr xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           </ns1:H323Trunk>
                           <ns1:TimeStamp>1494335117</ns1:TimeStamp>
                           <ns1:Protocol>SCCP</ns1:Protocol>
                           <ns1:NumOfLines>0</ns1:NumOfLines>
                           <ns1:LinesStatus/>
                           <ns1:ActiveLoadID xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:InactiveLoadID xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:DownloadStatus>Unknown</ns1:DownloadStatus>
                           <ns1:DownloadFailureReason xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:DownloadServer xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:IPAddress>
                              <ns1:item>
                                 <ns1:IP>10.106.0.104</ns1:IP>
                                 <ns1:IPAddrType>ipv4</ns1:IPAddrType>
                                 <ns1:Attribute>AdministrativeAndSignaling</ns1:Attribute>
                              </ns1:item>
                           </ns1:IPAddress>
                        </ns1:item>
                     </ns1:CmDevices>
                  </ns1:item>
                  <ns1:item>
                     <ns1:ReturnCode>Ok</ns1:ReturnCode>
                     <ns1:Name>10.0.5.127</ns1:Name>
                     <ns1:NoChange>false</ns1:NoChange>
                     <ns1:CmDevices>
                        <ns1:item>
                           <ns1:Name>SEP04DAD2BF58D4</ns1:Name>
                           <ns1:DirNumber>5173-Registered</ns1:DirNumber>
                           <ns1:DeviceClass>Phone</ns1:DeviceClass>
                           <ns1:Model>435</ns1:Model>
                           <ns1:Product>334</ns1:Product>
                           <ns1:BoxProduct>0</ns1:BoxProduct>
                           <ns1:Httpd>Yes</ns1:Httpd>
                           <ns1:RegistrationAttempts>0</ns1:RegistrationAttempts>
                           <ns1:IsCtiControllable>true</ns1:IsCtiControllable>
                           <ns1:LoginUserId xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:Status>Registered</ns1:Status>
                           <ns1:StatusReason>0</ns1:StatusReason>
                           <ns1:PerfMonObject>2</ns1:PerfMonObject>
                           <ns1:DChannel>0</ns1:DChannel>
                           <ns1:Description>114_BEL_CR-PH</ns1:Description>
                           <ns1:H323Trunk>
                              <ns1:ConfigName xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:TechPrefix xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:Zone xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer1 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer2 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer3 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:AltGkList xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:ActiveGk xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:CallSignalAddr xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RasAddr xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           </ns1:H323Trunk>
                           <ns1:TimeStamp>1494105234</ns1:TimeStamp>
                           <ns1:Protocol>SCCP</ns1:Protocol>
                           <ns1:NumOfLines>1</ns1:NumOfLines>
                           <ns1:LinesStatus>
                              <ns1:item>
                                 <ns1:DirectoryNumber>5173</ns1:DirectoryNumber>
                                 <ns1:Status>Registered</ns1:Status>
                              </ns1:item>
                           </ns1:LinesStatus>
                           <ns1:ActiveLoadID>SCCP45.9-4-2SR2-2S</ns1:ActiveLoadID>
                           <ns1:InactiveLoadID xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:DownloadStatus>Unknown</ns1:DownloadStatus>
                           <ns1:DownloadFailureReason xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:DownloadServer xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:IPAddress>
                              <ns1:item>
                                 <ns1:IP>10.114.2.14</ns1:IP>
                                 <ns1:IPAddrType>ipv4</ns1:IPAddrType>
                                 <ns1:Attribute>AdministrativeAndSignaling</ns1:Attribute>
                              </ns1:item>
                           </ns1:IPAddress>
                        </ns1:item>
                        <ns1:item>
                           <ns1:Name>SEP04DAD2BF6F3D</ns1:Name>
                           <ns1:DirNumber>8001-Registered</ns1:DirNumber>
                           <ns1:DeviceClass>Phone</ns1:DeviceClass>
                           <ns1:Model>435</ns1:Model>
                           <ns1:Product>334</ns1:Product>
                           <ns1:BoxProduct>0</ns1:BoxProduct>
                           <ns1:Httpd>Yes</ns1:Httpd>
                           <ns1:RegistrationAttempts>0</ns1:RegistrationAttempts>
                           <ns1:IsCtiControllable>true</ns1:IsCtiControllable>
                           <ns1:LoginUserId xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:Status>Registered</ns1:Status>
                           <ns1:StatusReason>0</ns1:StatusReason>
                           <ns1:PerfMonObject>2</ns1:PerfMonObject>
                           <ns1:DChannel>0</ns1:DChannel>
                           <ns1:Description>115_MCD_PHN</ns1:Description>
                           <ns1:H323Trunk>
                              <ns1:ConfigName xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:TechPrefix xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:Zone xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer1 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer2 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer3 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:AltGkList xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:ActiveGk xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:CallSignalAddr xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RasAddr xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           </ns1:H323Trunk>
                           <ns1:TimeStamp>1494259757</ns1:TimeStamp>
                           <ns1:Protocol>SCCP</ns1:Protocol>
                           <ns1:NumOfLines>1</ns1:NumOfLines>
                           <ns1:LinesStatus>
                              <ns1:item>
                                 <ns1:DirectoryNumber>8001</ns1:DirectoryNumber>
                                 <ns1:Status>Registered</ns1:Status>
                              </ns1:item>
                           </ns1:LinesStatus>
                           <ns1:ActiveLoadID>SCCP45.9-4-2SR2-2S</ns1:ActiveLoadID>
                           <ns1:InactiveLoadID xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:DownloadStatus>Unknown</ns1:DownloadStatus>
                           <ns1:DownloadFailureReason xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:DownloadServer xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:IPAddress>
                              <ns1:item>
                                 <ns1:IP>10.115.2.18</ns1:IP>
                                 <ns1:IPAddrType>ipv4</ns1:IPAddrType>
                                 <ns1:Attribute>AdministrativeAndSignaling</ns1:Attribute>
                              </ns1:item>
                           </ns1:IPAddress>
                        </ns1:item>
                     </ns1:CmDevices>
                  </ns1:item>
                  <ns1:item>
                     <ns1:ReturnCode>NotFound</ns1:ReturnCode>
                     <ns1:Name>10.0.5.128</ns1:Name>
                     <ns1:NoChange>true</ns1:NoChange>
                     <ns1:CmDevices xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  </ns1:item>
               </ns1:CmNodes>
            </ns1:SelectCmDeviceResult>
            <ns1:StateInfo>&lt;StateInfo>&lt;Node Name="10.0.5.125" SubsystemStartTime="1492659312" StateId="1478" TotalItemsFound="20" TotalItemsReturned="2"/>&lt;Node Name="10.0.5.127" SubsystemStartTime="1492661102" StateId="5649" TotalItemsFound="232" TotalItemsReturned="2"/>&lt;Node Name="10.0.5.128" SubsystemStartTime="0" StateId="0" TotalItemsFound="0" TotalItemsReturned="0"/>&lt;/StateInfo></ns1:StateInfo>
         </ns1:selectCmDeviceReturn>
      </ns1:selectCmDeviceResponse>
   </soapenv:Body>
</soapenv:Envelope>
String xmlText=File.ReadAllText(@“c:\temp\IPAddress.xml”);
XmlDocument doc=新的XmlDocument();
XmlNamespaceManager nsmgr=新的XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace(“soapenv”http://schemas.xmlsoap.org/soap/envelope/");
nsmgr.AddNamespace(“ns1”http://schemas.cisco.com/ast/soap/");
doc.LoadXml(xmlText);
XmlNodeList items=doc.SelectNodes(“/soapenv:Envelope/soapenv:Body/ns1:selectCmDeviceResponse/ns1:selectCmDeviceReturn/ns1:SelectCmDeviceResult/ns1:CmNodes/ns1:item/ns1:CmDevices/ns1:item”,nsmgr);
Console.WriteLine(doc.InnerText.ToString());
foreach(项中的XmlNode项)
{
字符串名称=GetNodeValue(项,“名称”);
字符串描述=GetNodeValue(项,“ns1:描述”);
字符串IpAddress=GetNodeValue(项,“ns1:IpAddress/ns1:item/ns1:IP”);
字符串DirNumber=GetNodeValue(项,“ns1:DirNumber”);
字符串类=GetNodeValue(项,“ns1:DeviceClass”);
字符串模型=GetNodeValue(项,“ns1:模型”);
字符串Product=GetNodeValue(项,“ns1:产品”);
更新信息(名称、IP地址);
}
}
以下是XML的一小部分:
4.
好啊
10.0.5.125
假的
SEP1CE6C7729944
4402未注册
电话
435
334
0
对
0
真的
厄琳·冈萨雷斯
未注册
8.
2.
0
105_GRN_LO-PH
1494272299
SCCP
1.
4402
未注册
SCCP45.9-4-2SR2-2S
不为人知
10.105.2.55
ipv4
行政和信号
SEP1CE6C772F3FB
电话
435
334
0
对
1.
真的
拒绝
27
0
0
1494335117
SCCP
0
不为人知
10.106.0.104
ipv4
行政和信号
好啊
10.0.5.127
假的
SEP04DAD2BF58D4
5173注册
电话
435
334
0
对
0
真的
登记
0
2.
0
114_BEL_CR-PH
1494105234
SCCP
1.