比较WPF中的XML文件 [英] Compare XML files in WPF

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

问题描述

您好b $ b

我正在为以下场景寻找WPF应用程序 -



比较WPF中的2个或更多XML文件使用树或数据网格像控件

和差异可以使用红色,绿色等颜色突出显示。



如果有人有任何样本或链接对于这种情况,请在这里分享。



干杯

Hi
I am looking for WPF application for below scenario-

Compare 2 or more XML files in WPF using tree or datagrid like controls
and differences can be highlighted using colors like red, green etc.

If anyone has any sample or link for this scenario please do share here.

Cheers

推荐答案

比较XML文件是一个坏主意。该文件可以具有相同的数据内容,并且格式和其他细节也不同。您可以逐字节比较两个文件,但不知道文件是XML(甚至文本文件)也不应该使用。为此,请使用类 System.IO.BinaryReader



如果您需要比较数据,最好的用法是类 System.Xml.XmlReader 。您只需读取中的所有XML(reader.Read()){/ * ... * /} 循环,如MSDN文档中的代码示例所示页面:

https: //msdn.microsoft.com/en-us/library/system.xml.xmlreader%28v=vs.110%29.aspx [ ^ ]。



只需要为两个文件使用两个读取器,并比较每个步骤的读取器数据。试验一下,快速了解它是如何工作的;它比解释更详细的更快。



-SA
Comparing XML files is a bad idea. The file can have identical data content and differ in formatting and other detail. You can compare two files byte by byte, but then no knowledge that the files are XML (or even text file) should not be used. For this purpose, use the class System.IO.BinaryReader.

If you need to compare data, the best thing to use is the class System.Xml.XmlReader. You just read all the XML in the while (reader.Read()) { /* ... */ } loop, as shown in the code sample on the MSDN documentation page:
https://msdn.microsoft.com/en-us/library/system.xml.xmlreader%28v=vs.110%29.aspx[^].

Only you need to use two readers for two files and compare readers data on each step. Experiment with that to quickly understand how it works; it will be faster than explanation of further detail.

—SA


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

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