在python中比较两个xml文件 [英] Comparing two xml files in python

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

问题描述

我是python编程的新手,并且在理解这个概念时遇到了一些麻烦.我希望比较两个xml文件.这些xml文件很大. 我将举一个我想比较的文件类型的例子.

I am new to programming in python,´and i have some troubles understanding the concept. I wish to compare two xml files. These xml files are quite large. I will give an example for the type of files i wish to compare.

xmlfile1:

<xml>
    <property1>
          <property2>    
               <property3>

               </property3>
          </property2>    
    </property1>    
</xml>

xml文件2:

<xml>
    <property1>
        <property2>    
            <property3> 
                <property4>

                </property4>    
            </property3>
        </property2>    
    </property1>

</xml>

我命名的property1,property2与文件中的实际属性不同. xml文件中有很多属性. 我希望比较两个xml文件.

the property1,property2 that i have named are different from the ones that are actually in the file. There are a lot of properties within the xml file. ANd i wish to compare the two xml files.

我正在使用lxml解析器来尝试比较两个文件并打印出它们之间的差异.

I am using an lxml parser to try to compare the two files and to print out the difference between them.

我不知道如何解析和自动比较它.

I do not know how to parse it and compare it automatically.

我尝试通读lxml解析器,但是我不明白如何将其用于我的问题.

I tried reading through the lxml parser, but i couldnt understand how to use it to my problem.

有人可以告诉我如何处理此问题.

Can someone please tell me how should i proceed with this problem.

代码段非常有用

还有一个问题,我是遵循正确的概念还是想念其他东西?请纠正您所知道的任何新概念

One more question, Am i following the right concept or i am missing something else? Please correct me of any new concepts that you knwo about

推荐答案

这实际上是一个具有挑战性的问题(由于差异"在旁观者的眼中常常意味着什么,因为在语义上会等同"您可能不想标记为差异的信息.

This is actually a reasonably challenging problem (due to what "difference" means often being in the eye of the beholder here, as there will be semantically "equivalent" information that you probably don't want marked as differences).

您可以尝试使用 xmldiff ,它基于论文

You could try using xmldiff, which is based on work in the paper Change Detection in Hierarchically Structured Information.

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

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