华途软件受控XML转EXCEL

      公司加密系统用的是华途的产品。最近公司高层想要重新梳理公司信息安全管理情况,华途加密系统的梳理和优化是重中之重。

      今天公司领导要求IT导出目前系统中所有软件、后缀的受控情况,然后IT吭哧吭哧地把华途软件中的XML发给领导了,结果领导根本不知道如何打开XML文件。等到领导用IE打开XML后,看到的是满屏幕的天书。IT的下场我只能说:老惨了。。。

      领导看到的XML如下图:

这个XML的格式还是很清晰的:ModuleInfo定义了软件的版本,进程标识,分类,控制类型等信息。  Include节点下面定义了要控制的文件后缀,Exclude节点下面定义了不控制的文件后缀。

所以,解决这个问题的思路很简单:通过代码读取这个XML文件,转义成领导能看懂的格式,存成EXCEL即可。

//定义结果集
scList = new List<SecureControl>();
//读取XML文件
string xmlFile = Path.Combine(Application.StartupPath, "XML", "config.xml");
XElement xele = XElement.Load(xmlFile);
//读取ModuleInfo节点集合
IList<XElement> a = xele.Descendants("ModuleInfo").ToList(); //ModuleInfo

foreach (XElement x in a)
{
try
{
//读取节点属性,取得软件版本等信息。
SecureControl sc = new SecureControl();
sc.IsCharacteristic = x.Attribute("IsCharacteristic").Value;
sc.IsControled = x.Attribute("IsControled").Value;
sc.Process = x.Attribute("Process").Value;
sc.SoftType = x.Attribute("SoftType").Value;
sc.SoftVersion = x.Attribute("SoftVersion").Value;
sc.Include = "";
sc.Exclude = "";
//遍历读取Include
IList<XElement> include = x.Descendants("Include").Descendants("FileType").ToList();
foreach (XElement ic in include)
{
sc.Include += (ic.Value + " ");
}
//遍历读取Exclude
IList<XElement> exclude = x.Descendants("Exclude").Descendants("FileType").ToList();
foreach (XElement ex in exclude)
{
sc.Exclude += (ex.Value + " ");
}
//插入结果集,用于显示
scList.Add(sc);
}
catch
{ }
}

gridControl1.DataSource = scList;

效果展示:

读取界面

存成的Excel:

猜你喜欢

转载自www.cnblogs.com/huangdashen/p/9805948.html
今日推荐