<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE ResourceObject PUBLIC "my_corp.dtd" "my_corp.dtd"><ResourceObjectdisplayName="TESTNGAD\AggUserFSP test"identity="CN=AggUserFSP test,OU=FSPAggeFrame,OU=unittests,DC=TestNGAD,DC=local"objectType="account"uuid="{97182a65-61f2-443c-b0fa-477d0821d8c4}"><Attributes><Map><entrykey="accountFlags"><value><List><String>Normal User Account</String><String>Password Cannot Expire</String></List></value></entry><entrykey="homePhone"value="6555"/><entrykey="l"value="Pune"/><entrykey="memberOf"><value><List><String>CN=FSPGRP2,OU=ADAggF,OU=unittests2,DC=AUTODOMAIN,DC=LOCAL</String><String>CN=FSPGRP1,OU=ADAggF,OU=unittests2,DC=AUTODOMAIN,DC=LOCAL</String><String>CN=LocalAggFrame,OU=FSPAggeFrame,OU=unittests,DC=TestNGAD,DC=local</String></List></value></entry><entrykey="objectClass"><value><List><String>top</String><String>person</String><String>organizationalPerson</String><String>user</String></List></value></entry><entrykey="sn"value="test"/><entrykey="st"value="MH"/><entrykey="streetAddress"value="SB ROAD"/><entrykey="title"value="QA"/><entrykey="userPrincipalName"value="AggUserFSP test@TestNGAD.local"/></Map></Attributes></ResourceObject>
And, following XPATH I tried to ignore the order of the elements but still it is not working, can someone help me out here? I referred the discussion here https://github.com/xmlunit/xmlunit/issues/123
diff = DiffBuilder
.compare(control)
.withTest(test)
.checkForSimilar().checkForIdentical() //ignore the order of 'elements` but check they are identical
.normalizeWhitespace()
.ignoreComments()
.ignoreWhitespace()
//.ignoreElementContentWhitespace()
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.conditionalBuilder()
.whenElementIsNamed("Attributes").thenUse(ElementSelectors.byXPath("./Map/entry[@key]", ElementSelectors.byNameAndText))
.elseUse(ElementSelectors.byName)
.build()))
.build();
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
checkForSimilar and checkForIdentical are mutually exclusive and the las one you set wins. Unless you you provide a DifferenceEvaluator that downgrades node order differences to IDENTICAL you will never get better than SIMILAR with swapped nodes.
So if you are really aiming for an identical result you will need to override the DifferenceEvaluator in use as well.
The ElementSelector's job is to make XMLUnit match the nodes with each other that you consider to be "the same nodes", it does not make node order differences go away.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've a XML as below
And, following XPATH I tried to ignore the order of the elements but still it is not working, can someone help me out here? I referred the discussion here https://github.com/xmlunit/xmlunit/issues/123
diff = DiffBuilder .compare(control) .withTest(test) .checkForSimilar().checkForIdentical() //ignore the order of 'elements` but check they are identical .normalizeWhitespace() .ignoreComments() .ignoreWhitespace() //.ignoreElementContentWhitespace() .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.conditionalBuilder() .whenElementIsNamed("Attributes").thenUse(ElementSelectors.byXPath("./Map/entry[@key]", ElementSelectors.byNameAndText)) .elseUse(ElementSelectors.byName) .build())) .build();
checkForSimilar
andcheckForIdentical
are mutually exclusive and the las one you set wins. Unless you you provide aDifferenceEvaluator
that downgrades node order differences toIDENTICAL
you will never get better thanSIMILAR
with swapped nodes.So if you are really aiming for an identical result you will need to override the
DifferenceEvaluator
in use as well.The
ElementSelector
's job is to make XMLUnit match the nodes with each other that you consider to be "the same nodes", it does not make node order differences go away.