我们能比较两个不同文件夹下两个同名的XML文件吗?

2024-10-02 22:28:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用XMLDiff来比较两个单独文件夹下的XML文件列表。我正在遍历两个文件夹中的文件列表,并在比较函数中逐个传递它们,在该函数中,我使用“diff_files”来识别文件中的差异

当我有两个不同的文件名时,它给了我如下的区别:

<somexmltag diff:insert="">ABCCCC</somexmltag > <somexmltag diff:delete="">XYZZZ</somexmltag >

但我需要比较两个同名文件。 是否可以使用xml diff实现这一点?下面是我尝试的示例代码:

def FileCompare (golden_path,golden_File,Output_path,Output_File):

try:
    gold_file=golden_File
    Out_file = Output_File
    gold_path=golden_path +"\\"+golden_File 
    Out_path =Output_path +"\\"+Output_File

    print('Files being compared',gold_path, gold_file, Out_path, Out_file)
    result = main.diff_files(gold_file, Out_file, formatter=formatting.XMLFormatter())
    print (result)

except:
    print(traceback.format_exc())
    pass

for x in range(0,len(Comm_Files)):
FileCompare(Source_Filenames[x][0],Comm_Files[x],Dest_Filenames[x][0],Comm_Files[x])

当我运行上述代码时,它不会显示差异,而是简单地打印解析的gold_文件(即文件夹1中的文件1),如下所示:

> Initializing Dialogue... Please select a directory. Files being
> compared Folder2 Path File1.xml, Folder 2 Path File1.xml
> <somexmltag>XYZZZ</somexmltag>  ... ...

Tags: 文件path文件夹outputdifffilesxmlout