什么是比较平等的XML文件的最好方法是什么?平等、文件、方法、XML

2023-09-03 01:22:59 作者:寄鸢

我使用的是.NET 2.0,而最近code修改已经失效我的previous Assert.AreEqual调用(这比XML​​的两个字符串)。只有一个元素的XML是在新的codeBase的实际上是不同的,所以我希望的是所有其他元素的比较,给我我想要的结果。比较需要通过编程完成,因为它是一个单元测试的一部分。

I'm using .NET 2.0, and a recent code change has invalidated my previous Assert.AreEqual call (which compared two strings of XML). Only one element of the XML is actually different in the new codebase, so my hope is that a comparison of all the other elements will give me the result I want. The comparison needs to be done programmatically, since it's part of a unit test.

起初,我正在考虑使用XmlDocument的一对夫妇的实例。但后来我发现这一点: http://drowningintechnicaldebt.com/blogs/scottroycraft/archive/2007/05/06/comparing-xml-files.aspx

At first, I was considering using a couple instances of XmlDocument. But then I found this: http://drowningintechnicaldebt.com/blogs/scottroycraft/archive/2007/05/06/comparing-xml-files.aspx

它看起来像它可能工作,但我的情况下感兴趣的堆栈溢出的反馈有一个更好的办法。

It looks like it might work, but I was interested in Stack Overflow feedback in case there's a better way.

我想避免添加其他依赖此,如果在所有可能的。

I'd like to avoid adding another dependency for this if at all possible.

有一个XML断言为NUnit的? 你会如何比较两个XML文档? Is there an XML asserts for NUnit? How would you compare two XML Documents?

推荐答案

这真的取决于你要检查的差异是什么。

It really depends on what you want to check as "differences".

目前,我们正在使用微软的xmldiff:http://msdn.microsoft.com/en-us/library/aa302294.aspx

Right now, we're using Microsoft XmlDiff: http://msdn.microsoft.com/en-us/library/aa302294.aspx