在C#中的XML的比较 [英] Xml Comparison in C#

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

问题描述

我试图比较使用C#code两个XML文件。
我想忽略XML语法的差异(即preFIX名称)。
对于我使用微软的<一个href=\"http://www.microsoft.com/downloads/details.aspx?FamilyID=3471df57-0c08-46b4-894d-f569aa7f7892&DisplayLang=en\">XML diff和patch C#API。
它适用于某些XML的,但我无法找到一个方法来配置它一起工作了以下两个XML的:

XML答:

 &LT;根系的xmlns:NS =HTTP:// myns名字&GT;
  &LT; NS:孩子&GT; 1 LT; / NS:孩子&GT;
&LT; /根&GT;

XML乙:

 &LT;根和GT;
  &LT;儿童的xmlns =HTTP:// myns名字&GT; 1 LT; /儿童&GT;
&LT; /根&GT;

我的问题是:


  1. 我说得对,这两个XML的在语义上是相等的(或同构)?

  2. 能否微软的XML diff和patch API进行配置,以支持它?

  3. 是否有任何其他C#工具来这样做呢?


解决方案

我有<一个href=\"http://social.msdn.microsoft.com/Forums/en-US/xmlandnetfx/thread/3f2bb47f-356d-48f3-866c-b2533e5731f8/\"相对=nofollow>马丁Honnen 在XML和.NET Framework MSDN论坛答案。
总之,他建议使用XQuery 1.0的深相等功能,并提供了一​​些C#实现。似乎工作。

I'm trying to compare two Xml files using C# code. I want to ignore Xml syntax differences (i.e. prefix names). For that I am using Microsoft's XML Diff and Patch C# API. It works for some Xml's but I couldn't find a way to configure it to work with the following two Xml's:

XML A:

<root xmlns:ns="http://myNs">
  <ns:child>1</ns:child>
</root>

XML B:

<root>
  <child xmlns="http://myNs">1</child>
</root>

My questions are:

  1. Am I right that these two xml's are semantically equal (or isomorphic)?
  2. Can Microsoft's XML Diff and Patch API be configured to support it?
  3. Are there any other C# utilities to to this?

解决方案

I've got an answer by Martin Honnen in XML and the .NET Framework MSDN Forum. In short he suggests to use XQuery 1.0's deep-equal function and supplies some C# implementations. Seems to work.

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

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