使用C#进行XML比较 [英] XML comparision using C#

查看:149
本文介绍了使用C#进行XML比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用两个diff xml我想比较xml中的所有元素而不显式指定元素名称。请有人帮帮我。紧急。

解决方案

请仔细阅读以下文章可能会有所帮助



http://deepumi.wordpress.com/2010/03/02/compare-xml -files-using-csharp-linq / [ ^ ]


考虑到您只想比较以了解xml是否相同

试一试





  bool  bReturn =  false ; 
XmlDocument xDoc = new XmlDocument();
XmlDocument xDoc2 = new XmlDocument();
xDoc.Load( XML Doc 1的路径);
xDoc2.Load( XML Doc 2的路径);
for int i = 0 ; i < xDoc.DocumentElement.ChildNodes.Count; i ++)
{
if (xDoc.DocumentElement.ChildNodes.Item(i).InnerXml!= xDoc2.DocumentElement.ChildNodes.Item(i).InnerXml)
{
bReturn = ; // Xml不相同
}
}


Hi,

am using two diff xml I want to compare all the elements in the xml without explicitly specifying element name. Please anyone help me. Its urgent.

解决方案

please go through the below article may be it helps

http://deepumi.wordpress.com/2010/03/02/compare-xml-files-using-csharp-linq/[^]


Considering that you just want to compare to know whether that the xml are same or not
Try this out


bool bReturn = false;
XmlDocument xDoc = new XmlDocument();
XmlDocument xDoc2 = new XmlDocument();
xDoc.Load("Path of the  XML Doc 1");
xDoc2.Load("Path of the  XML Doc 2");
for (int i = 0 ;i < xDoc.DocumentElement.ChildNodes.Count ; i++)
{
     if(xDoc.DocumentElement.ChildNodes.Item(i).InnerXml != xDoc2.DocumentElement.ChildNodes.Item(i).InnerXml)
     {
        bReturn = true; //Xml are not same
     }
}


这篇关于使用C#进行XML比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆