示例 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>
我一直在做一些教程,但我无法获取 files 元素中的所有文件列表。它只显示第一个 <File> 元素,不显示其余元素。这是我的代码:
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 中显示所有文件?