I am using xmlunit 2.5.0.
Below are my two xml string : One is the controlxml
and one is testxml
.
String controlXml = "<flowers><flower><f1 name = \"Roses\"/></flower><flower><f1 name = \"Daisy\"/></flower><flower><f1 name = \"Crocus\"/></flower></flowers>";
String testXml = "<flowers><flower><f1 name = \"Daisy\"/></flower><flower><f1 name = \"Roses\"/></flower><flower><f1 name = \"Crocus\"/></flower></flowers>";
Here i am comparing these two string xmls using xmlunit.
My java code is:
org.xmlunit.diff.Diff myDiff = DiffBuilder.compare(controlXml).withTest(testXml)
.checkForSimilar()
.withNodeMatcher(new
DefaultNodeMatcher(ElementSelectors.conditionalBuilder()
.whenElementIsNamed("f1")
.thenUse(ElementSelectors.byName)
.elseUse(ElementSelectors.byNameAndText)
.build()))
.build();
Getting error:
***********************
Expected attribute value 'Roses' but was 'Daisy' - comparing <f1 name="Roses"...> at /flowers[1]/flower[1]/f1[1]/@name to <f1 name="Daisy"...> at /flowers[1]/flower[1]/f1[1]/@name (DIFFERENT)
***********************
***********************
Expected attribute value 'Daisy' but was 'Roses' - comparing <f1 name="Daisy"...> at /flowers[1]/flower[2]/f1[1]/@name to <f1 name="Roses"...> at /flowers[1]/flower[2]/f1[1]/@name (DIFFERENT)
***********************
I want to get no error since Rose is present in the testxml. Why is Rose in controlxml is being compared to Daisy in testxml even though i have rose in the testxml and i have ElementSelectors.byName
and whenElementIsNamed("f1")
.
Which ElementSelector should I use?