验证Zip文件夹中的内容是否存在于XML元数据中且没有差异



我正在开发一个程序,该程序应该通过对XML元数据文件运行数字来检查Zip文件夹的内容,XML元数据文件将在Zip文件夹中传输。Zip文件夹中的其他文件为AFP格式。对于zip文件夹中包含的AFP,XML元数据标记应该定义一个元素,例如:

<file>
<name>AFP FILE NAME X</name>
<code>AFP FILE CODE Y</code>
<pagecount>AFP PAGE COUNT Z</pagecount>
</file>
<file>
<name>AFP FILE NAME A</name>
<code>AFP FILE CODE B</code>
<pagecount>AFP PAGE COUNT C</pagecount>
</file>
.
.
.

程序应根据各自的文件标签验证AFP内容。我正在使用一个内部库来加载和读取AFP的文件内容。我不能做的是阅读xml,然后将它们与各自的AFP事件进行比较,并报告所看到的任何问题。

使用xml-linq并将结果放入可用于比较的字典中

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:temptest.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
Dictionary<string, List<File>> dict = doc.Descendants("file")
.GroupBy(x => (string)x.Element("name"), y => new File() { code = (string)y.Element("name"), name = (string)y.Element("name"), pagecount = (string)y.Element("pagecount") })
.ToDictionary(x => x.Key, y => y.ToList());
}
}
public class File
{
public string name { get; set; }
public string code { get; set; }
public string pagecount { get; set; }
}
}

最新更新