【问题标题】:Java: Easiest way to compare two xmls [duplicate]Java:比较两个xml的最简单方法[重复]
【发布时间】:2012-02-15 00:56:44
【问题描述】:

我有两个 xml:

first.xml

<text>This is text</text>
<output>This is output</output>

second.xml

<text>This is not text</text>
<output>This is output</output>

我想比较这两个xml,输出应该是这样的

<text>This is <inserted>not</inserted> text</text>
    <output>This is output</output>

意思是,我想在新添加的文本中添加一个新标签假设&lt;inserted&gt;。 如何比较这些xml并创建一个新的?

感谢您的宝贵时间:)

【问题讨论】:

  • 我不会认为这是重复的,因为最初的问题是 3 1/2 年前的问题,并且解决方案 (XMLUnit) 已经超过 2 年没有发布了。另外,我不会考虑使用单元测试库来解决编程问题。

标签: java xml


【解决方案1】:

http://xmlunit.sourceforge.net/

很好用在单元测试中,输出非常好。

【讨论】:

  • 为什么你认为这个问题是关于测试的?这只是所谓重复的答案,并且是一个超过 2 年没有发布的库。
  • 因为我认为比较两个 XML 文件是否相同就像测试两个 XML 文件是否相同
  • @Farmor - 问题的主体清楚地表明 OP 想要 XML 文档之间的差异......而不仅仅是一个是/否的答案。
【解决方案2】:

看看diffxml

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-21
    • 1970-01-01
    • 2015-12-23
    • 2011-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多