在 C# 中解析 XML,创建用户 ID 列表

本文关键字:创建 用户 ID 列表 XML | 更新日期: 2023-09-27 18:36:47

我正在尝试从 C# 中的 xml 文档创建用户 ID 列表。这是我的最新尝试:

        string xml = WebexAutomation.LstSummaryUser();
        XDocument doc = XDocument.Parse(xml)
        var result = doc.Descendants("webExId").Single().Value;
        Console.WriteLine(result);

我的XML看起来像有多个用户,我正在尝试创建每个webExID的列表

<?xml version="1.0" encoding="ISO-8859-1"?>
<serv:message xmlns:serv="http://www.webex.com/schemas/2002/06/service" xmlns:com="http://www.webex.com/schemas/2002/06/common" xmlns:use="http://www.webex.com/schemas/2002/06/service/user">
<serv:header>
    <serv:response>
        <serv:result>SUCCESS</serv:result>
        <serv:gsbStatus>PRIMARY</serv:gsbStatus>
    </serv:response>
</serv:header>
<serv:body>
    <serv:bodyContent xsi:type="use:lstsummaryUserResponse" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <use:user>
            <use:webExId>kkkk</use:webExId>
            <use:firstName>kkkk</use:firstName>
            <use:lastName>llllll</use:lastName>
            <use:email>kkkkkk</use:email>
            <use:registrationDate>06/07/2014 01:17:13</use:registrationDate>
            <use:active>DEACTIVATED</use:active>
            <use:timeZoneID>11</use:timeZoneID>
        </use:user>
<use:user>
            <use:webExId>jjjj</use:webExId>
            <use:firstName>ssss</use:firstName>
            <use:lastName>dddd</use:lastName>
            <use:email>dfdfdf</use:email>
            <use:registrationDate>06/10/2013 12:23:52</use:registrationDate>
            <use:active>DEACTIVATED</use:active>
            <use:timeZoneID>11</use:timeZoneID>
        </use:user>
<use:matchingRecords>
            <serv:total>44</serv:total>
            <serv:returned>10</serv:returned>
            <serv:startFrom>1</serv:startFrom>
        </use:matchingRecords>
    </serv:bodyContent>
  </serv:body>
</serv:message>

有什么建议吗?

在 C# 中解析 XML,创建用户 ID 列表

试试这个

var webExId = XName.Get("webExId", "http://www.tempuri.org");
var webExIds = doc.Descendants(webExId);