gpt4 book ai didi

c# - C#获取xml文件中重复节点的信息

转载 作者:太空宇宙 更新时间:2023-11-03 19:12:58 24 4
gpt4 key购买 nike

我有一个 xml 文件如下:

<Root>
<Folder1>
<file>AAA</file>
<file>BBB</file>
<file>CCC</file>
</Folder1>
<Folder2>
<file>AAA</file>
<file>BBB</file>
<file>CCC</file>
</Folder2>
</Root>

我需要一个字符串列表中的所有 parent ,我尝试使用

using (XmlTextReader reader = new XmlTextReader(pathFiles))              
{
reader.ReadToFollowing("file");
string files = reader.ReadElementContentAsString();
}

因此,“files”变量只包含“AAA”,

reader.ReadElementContentAsString() 不接受列表。

有没有办法将输出提取为 {“AAA”,”BBB”,”CCC”, AAA”,”BBB”,”CCC”}

最佳答案

XDocument doc=XDocument.Load(xmlPath);
List<string> values=doc.Descendants("file")
.Select(x=>x.Value)
.ToList();

关于c# - C#获取xml文件中重复节点的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19288791/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com