示例XML元素的列表:无法获得使用LINQ to XML
<CONFIGURATION>
<Files>
<File>D:\Test\TestFolder\TestFolder1\TestFile.txt</File>
<File>D:\Test\TestFolder\TestFolder1\TestFile01.txt</File>
<File>D:\Test\TestFolder\TestFolder1\TestFile02.txt</File>
<File>D:\Test\TestFolder\TestFolder1\TestFile03.txt</File>
<File>D:\Test\TestFolder\TestFolder1\TestFile04.txt</File>
</Files>
<SizeMB>3</SizeMB>
<BackupLocation>D:\Log backups\File backups</BackupLocation>
</CONFIGURATION>
我一直在做一些教程,但我无法得到的文件元素中的所有文件列表。它仅显示第一个<文件>元素,并不显示其余部分。这是我的代码:
var fileFolders = from file in XDocument.Load(@"D:\Hello\backupconfig1.xml").Descendants("Files")
select new
{
File = file.Element("File").Value
};
foreach (var fileFolder in fileFolders)
{
Console.WriteLine("File = " + fileFolder.File);
}
如何在Files元素中显示所有文件,SizeMB和BackupLocation?
谢谢你的回答!有效!对不起,我的愚蠢的问题.. :) – Blackator