日期:2014-05-16 浏览次数:20389 次
/// <summary>
/// 更新XML文件
/// </summary>
/// <param name="itemNew">新XML文件</param>
/// <param name="itemOld">旧XML文件(需要更新的文件)</param>
private void UpdateXML(string itemNew, string itemOld)
{
XmlDocument xmlDocumentNew = new XmlDocument();
xmlDocumentNew.Load(itemNew);
XmlElement xmlElementNew = xmlDocumentNew.DocumentElement;
XmlDocument xmlDocumentOld = new XmlDocument();
xmlDocumentOld.Load(itemOld);
XmlElement xmlElementOld = xmlDocumentOld.DocumentElement;
if (xmlDocumentNew != null && xmlDocumentOld != null)
{
XmlNodeList xnListNew = xmlElementNew.ChildNodes;
XmlNodeList xnListOld = xmlElementOld.ChildNodes;
Hashtable hs = new Hashtable();
foreach (XmlNode item in xnListOld)
{
if (item.Attributes["Key"] != null)
{
if (!hs.Contains(item.Attributes["Key"].Value))
{
hs.Add(item.Attributes["Key"].Value, item.Attributes["Text"].Value);
}