如何读取多个名称空间和多个子节点具有相同名称的xml soap响应

时间:2017-01-04 23:32:20

标签: c# xml soap cisco

我们向cisco cucm发了一个肥皂请求并得到了这个结果。 我们需要读取此结果并获取每个设备(项目节点)的详细信息。 问题是有多个节点具有相同的名称" item" 什么是阅读它的最佳方式?



<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <ns1:selectCmDeviceResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://schemas.cisco.com/ast/soap">
            <SelectCmDeviceResult xsi:type="ns2:SelectCmDeviceResult" xmlns:ns2="http://ccm.cisco.com/serviceability/soap/risport70/">
                <TotalDevicesFound xsi:type="xsd:unsignedInt">12</TotalDevicesFound>
                <CmNodes soapenc:arrayType="ns2:CmNode[1]" xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
                    <item xsi:type="ns2:CmNode">
                        <ReturnCode xsi:type="ns2:RisReturnCode">Ok</ReturnCode>
                        <Name xsi:type="xsd:string">10.1.240.109</Name>
                        <NoChange xsi:type="xsd:boolean">false</NoChange>
                        <CmDevices soapenc:arrayType="ns2:CmDevice[12]" xsi:type="soapenc:Array">
                            <item xsi:type="ns2:CmDevice">
                                <Name xsi:type="xsd:string">10.1.240.6</Name>
                                <DirNumber xsi:type="xsd:string" xsi:nil="true"/>
                                <Class xsi:type="ns2:DeviceClass">H323</Class>
                                <Model xsi:type="xsd:unsignedInt">62</Model>
                                <Product xsi:type="xsd:unsignedInt">17</Product>
                                <BoxProduct xsi:type="xsd:unsignedInt">0</BoxProduct>
                                <Httpd xsi:type="ns2:CmDevHttpd">No</Httpd>
                                <RegistrationAttempts xsi:type="xsd:unsignedInt">0</RegistrationAttempts>
                                <IsCtiControllable xsi:type="xsd:boolean">false</IsCtiControllable>
                                <LoginUserId xsi:type="xsd:string" xsi:nil="true"/>
                                <Status xsi:type="ns2:CmDevRegStat">Unknown</Status>
                                <StatusReason xsi:type="xsd:unsignedInt">0</StatusReason>
                                <PerfMonObject xsi:type="xsd:unsignedInt">0</PerfMonObject>
                                <DChannel xsi:type="xsd:unsignedInt">0</DChannel>
                                <Description xsi:type="xsd:string">10.1.240.6</Description>
                                <H323Trunk xsi:type="ns2:H323Trunk">
                                    <ConfigName xsi:type="xsd:string" xsi:nil="true"/>
                                    <TechPrefix xsi:type="xsd:string" xsi:nil="true"/>
                                    <Zone xsi:type="xsd:string" xsi:nil="true"/>
                                    <RemoteCmServer1 xsi:type="xsd:string" xsi:nil="true"/>
                                    <RemoteCmServer2 xsi:type="xsd:string" xsi:nil="true"/>
                                    <RemoteCmServer3 xsi:type="xsd:string" xsi:nil="true"/>
                                    <AltGkList xsi:type="xsd:string" xsi:nil="true"/>
                                    <ActiveGk xsi:type="xsd:string" xsi:nil="true"/>
                                    <CallSignalAddr xsi:type="xsd:string" xsi:nil="true"/>
                                    <RasAddr xsi:type="xsd:string" xsi:nil="true"/>
                                </H323Trunk>
                                <TimeStamp xsi:type="xsd:unsignedInt">0</TimeStamp>
                                <Protocol xsi:type="ns2:ProtocolType">Any</Protocol>
                                <NumOfLines xsi:type="xsd:unsignedInt">0</NumOfLines>
                                <LinesStatus soapenc:arrayType="ns2:CmDevSingleLineStatus[0]" xsi:type="soapenc:Array"/>
                                <ActiveLoadID xsi:type="xsd:string" xsi:nil="true"/>
                                <InactiveLoadID xsi:type="xsd:string" xsi:nil="true"/>
                                <DownloadStatus xsi:type="ns2:DeviceDownloadStatus">Unknown</DownloadStatus>
                                <DownloadFailureReason xsi:type="xsd:string" xsi:nil="true"/>
                                <DownloadServer xsi:type="xsd:string" xsi:nil="true"/>
                                <IPAddress soapenc:arrayType="ns2:IPAddressArrayType[1]" xsi:type="soapenc:Array">
                                    <item xsi:type="ns2:IPAddressArrayType">
                                        <IP xsi:type="xsd:string">10.1.240.6</IP>
                                        <IPAddrType xsi:type="ns2:IPAddrType">ipv4</IPAddrType>
                                        <Attribute xsi:type="ns2:AttributeType">Unknown</Attribute>
                                    </item>
                                </IPAddress>
                            </item>
                            <item xsi:type="ns2:CmDevice">
                                <Name xsi:type="xsd:string">10.1.240.7</Name>
                                <DirNumber xsi:type="xsd:string" xsi:nil="true"/>
                                <Class xsi:type="ns2:DeviceClass">H323</Class>
                                <Model xsi:type="xsd:unsignedInt">62</Model>
                                <Product xsi:type="xsd:unsignedInt">17</Product>
                                <BoxProduct xsi:type="xsd:unsignedInt">0</BoxProduct>
                                <Httpd xsi:type="ns2:CmDevHttpd">No</Httpd>
                                <RegistrationAttempts xsi:type="xsd:unsignedInt">0</RegistrationAttempts>
                                <IsCtiControllable xsi:type="xsd:boolean">false</IsCtiControllable>
                                <LoginUserId xsi:type="xsd:string" xsi:nil="true"/>
                                <Status xsi:type="ns2:CmDevRegStat">Unknown</Status>
                                <StatusReason xsi:type="xsd:unsignedInt">0</StatusReason>
                                <PerfMonObject xsi:type="xsd:unsignedInt">0</PerfMonObject>
                                <DChannel xsi:type="xsd:unsignedInt">0</DChannel>
                                <Description xsi:type="xsd:string">10.1.240.7</Description>
                                <H323Trunk xsi:type="ns2:H323Trunk">
                                    <ConfigName xsi:type="xsd:string" xsi:nil="true"/>
                                    <TechPrefix xsi:type="xsd:string" xsi:nil="true"/>
                                    <Zone xsi:type="xsd:string" xsi:nil="true"/>
                                    <RemoteCmServer1 xsi:type="xsd:string" xsi:nil="true"/>
                                    <RemoteCmServer2 xsi:type="xsd:string" xsi:nil="true"/>
                                    <RemoteCmServer3 xsi:type="xsd:string" xsi:nil="true"/>
                                    <AltGkList xsi:type="xsd:string" xsi:nil="true"/>
                                    <ActiveGk xsi:type="xsd:string" xsi:nil="true"/>
                                    <CallSignalAddr xsi:type="xsd:string" xsi:nil="true"/>
                                    <RasAddr xsi:type="xsd:string" xsi:nil="true"/>
                                </H323Trunk>
                                <TimeStamp xsi:type="xsd:unsignedInt">0</TimeStamp>
                                <Protocol xsi:type="ns2:ProtocolType">Any</Protocol>
                                <NumOfLines xsi:type="xsd:unsignedInt">0</NumOfLines>
                                <LinesStatus soapenc:arrayType="ns2:CmDevSingleLineStatus[0]" xsi:type="soapenc:Array"/>
                                <ActiveLoadID xsi:type="xsd:string" xsi:nil="true"/>
                                <InactiveLoadID xsi:type="xsd:string" xsi:nil="true"/>
                                <DownloadStatus xsi:type="ns2:DeviceDownloadStatus">Unknown</DownloadStatus>
                                <DownloadFailureReason xsi:type="xsd:string" xsi:nil="true"/>
                                <DownloadServer xsi:type="xsd:string" xsi:nil="true"/>
                                <IPAddress soapenc:arrayType="ns2:IPAddressArrayType[1]" xsi:type="soapenc:Array">
                                    <item xsi:type="ns2:IPAddressArrayType">
                                        <IP xsi:type="xsd:string">10.1.240.7</IP>
                                        <IPAddrType xsi:type="ns2:IPAddrType">ipv4</IPAddrType>
                                        <Attribute xsi:type="ns2:AttributeType">Unknown</Attribute>
                                    </item>
                                </IPAddress>
                            </item>
                            <item xsi:type="ns2:CmDevice">
                                <Name xsi:type="xsd:string">10.1.3.67</Name>
                                <DirNumber xsi:type="xsd:string" xsi:nil="true"/>
                                <Class xsi:type="ns2:DeviceClass">H323</Class>
                                <Model xsi:type="xsd:unsignedInt">62</Model>
                                <Product xsi:type="xsd:unsignedInt">17</Product>
                                <BoxProduct xsi:type="xsd:unsignedInt">0</BoxProduct>
                                <Httpd xsi:type="ns2:CmDevHttpd">No</Httpd>
                                <RegistrationAttempts xsi:type="xsd:unsignedInt">0</RegistrationAttempts>
                                <IsCtiControllable xsi:type="xsd:boolean">false</IsCtiControllable>
                                <LoginUserId xsi:type="xsd:string" xsi:nil="true"/>
                                <Status xsi:type="ns2:CmDevRegStat">Unknown</Status>
                                <StatusReason xsi:type="xsd:unsignedInt">0</StatusReason>
                                <PerfMonObject xsi:type="xsd:unsignedInt">0</PerfMonObject>
                                <DChannel xsi:type="xsd:unsignedInt">0</DChannel>
                                <Description xsi:type="xsd:string">10.1.240.118</Description>
                                <H323Trunk xsi:type="ns2:H323Trunk">
                                    <ConfigName xsi:type="xsd:string" xsi:nil="true"/>
                                    <TechPrefix xsi:type="xsd:string" xsi:nil="true"/>
                                    <Zone xsi:type="xsd:string" xsi:nil="true"/>
                                    <RemoteCmServer1 xsi:type="xsd:string" xsi:nil="true"/>
                                    <RemoteCmServer2 xsi:type="xsd:string" xsi:nil="true"/>
                                    <RemoteCmServer3 xsi:type="xsd:string" xsi:nil="true"/>
                                    <AltGkList xsi:type="xsd:string" xsi:nil="true"/>
                                    <ActiveGk xsi:type="xsd:string" xsi:nil="true"/>
                                    <CallSignalAddr xsi:type="xsd:string" xsi:nil="true"/>
                                    <RasAddr xsi:type="xsd:string" xsi:nil="true"/>
                                </H323Trunk>
                                <TimeStamp xsi:type="xsd:unsignedInt">0</TimeStamp>
                                <Protocol xsi:type="ns2:ProtocolType">Any</Protocol>
                                <NumOfLines xsi:type="xsd:unsignedInt">0</NumOfLines>
                                <LinesStatus soapenc:arrayType="ns2:CmDevSingleLineStatus[0]" xsi:type="soapenc:Array"/>
                                <ActiveLoadID xsi:type="xsd:string" xsi:nil="true"/>
                                <InactiveLoadID xsi:type="xsd:string" xsi:nil="true"/>
                                <DownloadStatus xsi:type="ns2:DeviceDownloadStatus">Unknown</DownloadStatus>
                                <DownloadFailureReason xsi:type="xsd:string" xsi:nil="true"/>
                                <DownloadServer xsi:type="xsd:string" xsi:nil="true"/>
                                <IPAddress soapenc:arrayType="ns2:IPAddressArrayType[1]" xsi:type="soapenc:Array">
                                    <item xsi:type="ns2:IPAddressArrayType">
                                        <IP xsi:type="xsd:string">10.1.3.67</IP>
                                        <IPAddrType xsi:type="ns2:IPAddrType">ipv4</IPAddrType>
                                        <Attribute xsi:type="ns2:AttributeType">Unknown</Attribute>
                                    </item>
                                </IPAddress>
                            </item>
</CmDevices>
                    </item>
                </CmNodes>
            </SelectCmDeviceResult>
            <ns1:StateInfo xsi:type="xsd:string">&lt;StateInfo ClusterWide=&quot;1&quot;&gt;&lt;Node Name=&quot;10.1.240.109&quot; SubsystemStartTime=&quot;1476849576&quot; StateId=&quot;100&quot; TotalItemsFound=&quot;12&quot; TotalItemsReturned=&quot;12&quot;/&gt;&lt;/StateInfo&gt;</ns1:StateInfo>
        </ns1:selectCmDeviceResponse>
    </soapenv:Body>
</soapenv:Envelope> 
&#13;
&#13;
&#13;

感谢

1 个答案:

答案 0 :(得分:0)

尝试这样的事情

echo >&2