xmlunit

Compare two XML strings ignoring element order

偶尔善良 提交于 2019-11-27 17:17:04
问题 Suppose I have two xml strings <test> <elem>a</elem> <elem>b</elem> </test> <test> <elem>b</elem> <elem>a</elem> </test> How to write a test that compares those two strings and ignores the element order? I want the test to be as short as possible, no place for 10-line XML parsing etc. I'm looking for a simple assertion or something similar. I have this (which doesn't work) Diff diff = XMLUnit.compareXML(expectedString, actualString); XMLAssert.assertXMLEqual("meh", diff, true); 回答1: My

How do I ignore certain elements when comparing XML?

♀尐吖头ヾ 提交于 2019-11-26 22:32:45
I have an XML message like so: <root> <elementA>something</elementA> <elementB>something else</elementB> <elementC>yet another thing</elementC> </root> I want to compare a message of this type produced by a method under test to an expected message, but I don't care about elementA . So, I'd like the above message to be considered equal to: <root> <elementA>something different</elementA> <elementB>something else</elementB> <elementC>yet another thing</elementC> </root> I'm using the latest version of XMLUnit . I'm imagining that the answer involves creating a custom DifferenceListener ; I just

How do I ignore certain elements when comparing XML?

◇◆丶佛笑我妖孽 提交于 2019-11-26 08:22:26
问题 I have an XML message like so: <root> <elementA>something</elementA> <elementB>something else</elementB> <elementC>yet another thing</elementC> </root> I want to compare a message of this type produced by a method under test to an expected message, but I don\'t care about elementA . So, I\'d like the above message to be considered equal to: <root> <elementA>something different</elementA> <elementB>something else</elementB> <elementC>yet another thing</elementC> </root> I\'m using the latest