Question about Diff with Multiple Levels

  • Anonymous - 2010-08-12

    I am using XMLUnit to perform a diff on the following two XML strings:

    control: <root><name>A</name><name>B</name><name>C</name><title>Title</title><date>2010</date></root>
    test: <root><names>ABC</names><title>Title</title><date>2009</date></root>

    As expected, the differences have "deletions" for the "name" elements in the control, and "insert" for the "names" element in the test string.

    However, I am getting a "delete" for the control date element, and "insert" for the test date element,
    instead of a text change ( difference id = 14).

    I have tried  MultiLevelElementNameAndTextQualifier() with level set to 1 and 2, and also ElementNameAndTextQualifier(),
    and results are always the same.

    Is there a solution?

  • Anonymous - 2010-08-12

    If I used ElementNameQualifier, then the diff does return a text change for the "date" element.
    However, the documents I am working with have multiple levels of XML elements, and need to be compared on name and text because of multiple siblings with the same element name.  For example, in the case

    control <para>A</para><para>C</para>
    test <para>A</para><para>B</para><para>C</para>

    The diff compares "C" and "B", instead of declaring "B" as inserted.

  • Stefan Bodewig

    Stefan Bodewig - 2010-08-17

    So in one case you want XMLUnit to use nested text to identify matching elements and in a different case within the same document you don't.  This isn't anything any of the built-in ElementQualifiers can do, they are too generic for your usecase.

    The only option you have is to use your own implementation of ElementQualifier which might look ate the element name and the decide whether it needs to consult the nested text (if the local name is para) or not - if it has to, it could delegate to a ElementNameQualifier instance, otherwise it would only match the local names or whatever logic is appropriate in your case.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks