如何将XML文件加载到字典中?

时间:2014-08-14 13:59:49

标签: c# xml

编辑问题:

根据Jon SKeet的建议,我使用LINQ to XML。并提出以下内容。现在我如何将LINQ object1与object2.T进行比较。下面给出了test.xml的内容。 test2.xml只是没有从test.xml中取出最后一个节点。我现在如何比较这两个LINQ对象system1和system2

    XElement xelement1 = XElement.Load("C:\\test.xml");
IEnumerable<XElement> system1 = xelement1.Elements();


XElement xelement2 = XElement.Load("C:\\test2.xml");
IEnumerable<XElement> system2 = xelement2.Elements();


foreach (var config1 in system1)
{ 
      richTextBox1.AppendText("NAME: " + config1.Element("DisplayName").Value + Environment.NewLine );
      richTextBox1.AppendText("VERISON: " + config1.Element("DisplayVersion").Value + Environment.NewLine );
      richTextBox1.AppendText("DATE: " + config1.Element("InstallDate").Value + Environment.NewLine);
      richTextBox1.AppendText("PUBLISHER: " + config1.Element("Publisher").Value + Environment.NewLine);
      richTextBox1.AppendText(Environment.NewLine); 
}



foreach (var config2 in system2)
{
    richTextBox2.AppendText("NAME: " + config2.Element("DisplayName").Value + Environment.NewLine);
    richTextBox2.AppendText("VERISON: " + config2.Element("DisplayVersion").Value + Environment.NewLine);
    richTextBox2.AppendText("DATE: " + config2.Element("InstallDate").Value + Environment.NewLine);
    richTextBox2.AppendText("PUBLISHER: " + config2.Element("Publisher").Value + Environment.NewLine);
    richTextBox2.AppendText(Environment.NewLine);
}


    <Software_List>
<Configuration>
<DisplayName>Adobe Reader X (10.1.10)</DisplayName> 
<DisplayVersion>10.1.10</DisplayVersion> 
<InstallDate>20140630</InstallDate> 
<Publisher>Adobe Systems Incorporated</Publisher>
</Configuration>
<Configuration>
<DisplayName>Adobe Shockwave Player 12.1</DisplayName> 
<DisplayVersion>12.1.3.153</DisplayVersion> 
<InstallDate>20140714</InstallDate> 
<Publisher>Adobe Systems, Inc</Publisher>
</Configuration>
<Configuration>
<DisplayName>Citrix Receiver</DisplayName> 
<DisplayVersion>14.1.0.0</DisplayVersion> 
 <InstallDate></InstallDate> 
<Publisher>Citrix Systems, Inc.</Publisher>
</Configuration>
</Software_List>

0 个答案:

没有答案