4 回答

TA貢獻1772條經(jīng)驗 獲得超5個贊
在Python中:
import filecmp
cmp = filecmp.cmp('file_1.xml', 'file_2.xml')
# Files are equal
if cmp:
continue
else:
out_file.write('file_1.xml')

TA貢獻1998條經(jīng)驗 獲得超6個贊
使用 xmlunit 時髦:
@Grab(group='xmlunit', module='xmlunit', version='1.6')
import org.custommonkey.xmlunit.XMLUnit
XMLUnit.setIgnoreWhitespace(true)
def r1 = new File('/11/1.xml').newReader("UTF-8")
def r2 = new File('/11/2.xml').newReader("UTF-8")
def diff = XMLUnit.compareXML(r1, r2)
assert diff.similar()

TA貢獻1798條經(jīng)驗 獲得超7個贊
對于 Java,類似
public static void main(String[] args) throws IOException {
File file1 = new File("aaa.xml");
File file2 = new File("bbb.xml");
boolean areTwoFilesEqual = FileUtils.contentEquals(file1, file2);
System.out.println("Two files are equal?" + areTwoFilesEqual);
}
將使用Apache Commons IO API來完成這項工作。

TA貢獻1946條經(jīng)驗 獲得超3個贊
您可以使用 TreeOps 可視化工具 https://github.com/treeops/treeops 比較兩個 XML 文件。它轉換和比較 XML/JSON/CSV 中的樹數(shù)據(jù)。用戶可以選擇要通過比較忽略的路徑。
TreeOps 定義了一組數(shù)據(jù)樹轉換,以促進典型的數(shù)據(jù)操作:
過濾和刪除不相關的數(shù)據(jù)
重命名節(jié)點并沿樹移動節(jié)點
拼合和取消拼合以在樹格式和表格格式之間進行轉換
在選定節(jié)點下使用正則表達式更改節(jié)點
添加回答
舉報