From: Stefan B. <bo...@ap...> - 2011-02-21 05:30:11
|
On 2011-02-16, Pedro Lemos wrote: > Hi people, > I just started using XMLUnit in some of my projects and at the moment I'm > stuck with the following problem: > Imagine that I have a control file (control.xml) and a test file (test.xml) > which I want them to be analyzed as similar. > When I run the following code: > final String control = >> ResourceUtils.loadResourceString("control.xml"); >> final String test = ResourceUtils.loadResourceString("test.xml"); >> final Diff diff = new Diff(control, test); >> diff.overrideElementQualifier(new >> MultiLevelElementNameAndTextQualifier(5, true)); >> XMLAssert.assertXMLEqual(diff, true); > The result I get is that the files are similar. > Although, if I *uncomment *the existent elements, the result is that the > files are not equal. > *What do I need to do in my code so that those files be analyzed as being > similar to each other?* Figuring out the ElementQualifier is the biggest pain point in current XMLUnit. MultiLevelElementNameAndTextQualifier works under very specific circumstances that are no longer true when you uncomment the elements - since now suddenly there are more elements with nested text. There is no built-in ElementQualifier that would be able to select the Assertion elements you want to compare. You could write your own that basically acted as ElementNameQualifier and only if the element name was org.openehr.am.archetype.assertion.Assertion then dived down the tree and compared the pattern elements' text content. Stefan |