两个Xml文件的比较 [英] Comparison of Two Xml Files

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

问题描述



您能否帮助我使用VBA比较两个xml文件并在第三个xml文件中进行区别.

谢谢...

Hi,

Can you please help me to compare two xml files using VBA and make the differences in the third xml file.

Thanks...

推荐答案

差异"的含义在很大程度上取决于您的定义方式,尤其是在XML模式使用及其在应用程序上的映射上. 差异"文件.

首先,您需要找到的不是XML之间的差异,而是XML的逻辑结构之间的差异.相同的逻辑结构可以由文本以许多略有不同的方式表示.这是关于XML的关键思想之一:从逻辑结构中抽象出物理实体.特别是,您可以将两个要比较的文件解析为DOM,以比较DOM,而不是文件.但是如何表达比较结果呢?

现在,关于将差异映射到某些模式.我举一个简单的例子:

文件#1:
What do you mean by the "difference" highly depends on how you define it, in particular, in XML schema uses and its mapping onto the "difference" file.

First of all, you need to find difference not between files, but between logical structures of the XML. The same logical structure could be represented by text in many slightly different ways. This is one of the key ideas about XML: to abstract out physical entities from the logical structure. In particular, you could parse both files to be compared into DOM to compare DOMs, not files. But how to express the result of comparison?

Now, about mapping of differences to some schema. I''ll give you a simple example:

File #1:
<?xml version="1.0" encoding="UTF-8"?>
<top>
  <a>
    <b><![CDATA[<p>Same thing</p>]]></b>
    <b>1</b>
    <b>2</b>
  </a>
</top>



文件#2:



File#2:

<?xml version="1.0" encoding="UTF-8"?>
<top>
  <a>
    <b>&lt;p&gt;Same thing&lt;/p&gt;</b>
    <b>2</b>
    <b>3</b>
  </a>
</top>



有些数据在两个文件中,有些仅在其中一个文件中,有些仅在第二个文件中.
让我们考虑一下如何表示.例如,如下所示:



Some data is in both files, some in one of them only, some in the second one only.
Let''s think how it can be represented. For example, like this:

<?xml version="1.0" encoding="UTF-8"?>
<top>
   <a>
      <both_files>
         <b><b>&lt;p&gt;Same thing&lt;/p&gt;</b></b>
         <b>2</b>
      </both_files>
      <first_file_only>
         <b>1</b>
      </first_file_only>
      <second_file_only>
         <b>3</b>
      </second_file_only>
   </a>
</top>



首先,请注意,尽管写入方式不同,但两个文件中的第一个a元素都是相同的.
现在,差异"文件的模式是什么?这是比较中的文件的架构未自动定义的内容.我的示例以多种可能的方式之一使用了我编写的任意语法.而且我什至没有碰到像元素排序这样的难题.如何表达不同的顺序?嗯,这也是可行的,但是...

该问题没有一个通用的解决方案.我说清楚了吗?



一些链接,如果您需要更好地理解我所说的映射"问题:
http://en.wikipedia.org/wiki/Bijection [ http://en.wikipedia.org/wiki/Data_mapping [



First, pay attention that the first a element is identical in both files despite of different ways it''s written.
Now, what a schema for the "difference" file could be? This is something not automatically defined by the schema of the files under comparison. My sample uses some arbitrary syntax I made up — in one of many possible ways. And I did not even touch such a difficult problem as the ordering of elements. How to express the different ordering? Well, it''s feasible, too, but…

The problem does not have one general solution. Did I make it clear?



Some links, if you need to understand better what I''m talking about questioning the "mapping":
http://en.wikipedia.org/wiki/Bijection[^],
http://en.wikipedia.org/wiki/Data_mapping[^].

[END EDIT]

So the question as such does not have exact meaning.

—SA


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

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