Skip to content

ElementSelectors.byNameAndText doesnt ignore the order of nodes #115

@merajani

Description

@merajani

Hi,

I am quite impressed with the library and its documentation. Thanks for providing all the support. I have seen your issues #77 suggesting to use ElementSelectors.byNameAndText for ignoring the order of elements.

However if i have XML's something like this, the XMLUnit comparison fails to believe that its the same XML structure.

XML Control:

<root>
<parent><line>
<segment>L</segment>
</line>
<line>
<segment>K</segment>
</line>
<line>
<segment>P</segment>
</line>
</root>

<root>
<parent><line>
<segment>P</segment>
</line>
<line>
<segment>K</segment>
</line>
<line>
<segment>L</segment>
</line>
</root>

Here is my code:

Diff myDiff = DiffBuilder.compare(control).withTest(test).checkForSimilar().
withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)).build();
if(myDiff.hasDifferences())
Iterator iterator = myDiff.getDifferences().iterator();
while(iterator.hasNext())
Difference diff = iterator.next();
System.out.println(diff.getComparison().toString)
}

Please let me know what am i missing here, essentially these two structures of XML are same in different Line element order.

Also, I wanted to ignore white space between elements, i have considered using normalizeWhiteSpace and ignoreWhiteSpace API but they essentially remove the spaces from the text content as well.
Below both XML's are same except element 'line' is in next time for one of the XML structure.

<root>
<parent><line>
<segment>L</segment>
</line>
<line>
<segment>K</segment>
</line>
<line>
<segment>P</segment>
</line>
</root>

<root>
<parent>
<line>
<segment>P</segment>
</line>
<line>
<segment>K</segment>
</line>
<line>
<segment>L</segment>
</line>
</root>

I really appreciate your help, I spent quite a bit of time figuring this out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions