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

C# 如何读取具有多个名称空间且多个子节点具有相同名称的xml soap响应,c#,xml,soap,cisco,C#,Xml,Soap,Cisco,我们向cisco cucm做了一个soap请求,得到了这个结果。 我们需要读取此结果并获得每个设备(项目节点)的详细信息。 问题是有多个节点具有相同的名称“item” 最好的阅读方式是什么 12 好啊 10.1.240.109 假的 10.1.240.6 H323 62 17 0 不 0 假的 不为人知 0 0 0 10.1.240.6 0 任何 0 不为人知 10.1.240.6 ipv4 不为人知 10.1.240.7 H323 62 17 0 不 0 假的 不为人知 0 0 0 10.

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


12
好啊
10.1.240.109
假的
10.1.240.6
H323
62
17
0
不
0
假的
不为人知
0
0
0
10.1.240.6
0
任何
0
不为人知
10.1.240.6
ipv4
不为人知
10.1.240.7
H323
62
17
0
不
0
假的
不为人知
0
0
0
10.1.240.7
0
任何
0
不为人知
10.1.240.7
ipv4
不为人知
10.1.3.67
H323
62
17
0
不
0
假的
不为人知
0
0
0
10.1.240.118
0
任何
0
不为人知
10.1.3.67
ipv4
不为人知
StateInfo ClusterWide=“1”Node Name=“10.1.240.109”SubsystemStartTime=“1476849576”StateId=“100”TotalItemsFound=“12”totalItemsReturn=“12”//StateInfo

试试这样的方法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            XDocument doc = XDocument.Load(FILENAME);

            List<XElement> selectCmDeviceResult = doc.Descendants().Where(x => x.Name.LocalName == "SelectCmDeviceResult").ToList();

            var results = selectCmDeviceResult.Select(x => new {
                selectCmDeviceResult = (int)x.Element("TotalDevicesFound"),
                item = x.Element("CmNodes").Elements("item").Select(y => new {
                    returnCode = (string)y.Element("ReturnCode"),
                    name = (string)y.Element("Name"),
                    noChange = (Boolean)y.Element("NoChange"),
                    items = y.Element("CmDevices").Elements("item").Select(z => new {
                        name = (string)z.Element("Name"),
                        dirNumber = (string)z.Element("DirNumber"),
                        _class = (string)z.Element("Class"),
                        model = (int)z.Element("Model"),
                        product = (int)z.Element("Product"),
                        boxProduct = (int)z.Element("BoxProduct"),
                        httpd = (string)z.Element("Httpd"),
                        registrationAttempts = (int)z.Element("RegistrationAttempts"),
                        isCtiControllable = (Boolean)z.Element("IsCtiControllable"),
                        loginUserId = (string)z.Element("LoginUserId"),
                        status = (string)z.Element("Status"),
                        statusReason = (string)z.Element("StatusReason"),
                        perfMonObject = (int)z.Element("PerfMonObject"),
                        dChannel = (int)z.Element("DChannel"),
                        description = (string)z.Element("Description"),
                        timeStamp = (int)z.Element("TimeStamp"),
                        protocol = (string)z.Element("Protocol"),
                        numOfLines = (int)z.Element("NumOfLines"),
                        ipAddress = z.Elements("IPAddress").Select(a => new {
                            ip = (string)a.Descendants("IP").FirstOrDefault(),
                            ipAddressType = (string)a.Descendants("IPAddrType").FirstOrDefault(),
                            attribute = (string)a.Descendants("Attribute").FirstOrDefault()
                        }).FirstOrDefault()
                    }).ToList()
                }).FirstOrDefault()
            }).FirstOrDefault();

        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Xml;
使用System.Xml.Linq;
命名空间控制台应用程序1
{
班级计划
{
常量字符串文件名=@“c:\temp\test.xml”;
静态void Main(字符串[]参数)
{