Skip to content

Instantly share code, notes, and snippets.

@bodewig
Created December 17, 2019 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bodewig/573c4d9c3bb692028d1013c9ce74f8fd to your computer and use it in GitHub Desktop.
Save bodewig/573c4d9c3bb692028d1013c9ce74f8fd to your computer and use it in GitHub Desktop.
Testcase for Issue 169 in XMLUnit for Java
import org.xmlunit.builder.*;
import org.xmlunit.diff.*;
/**
* @see "https://github.com/xmlunit/xmlunit/issues/169"
*/
public class Issue169 {
private static final String X1 = "<Data:Keys xmlns:Data=\"foo\">\n"
+ "<Data:Value Key=\"1\" Name=\"Example1\" />\n"
+ "<Data:Value Key=\"2\" Name=\"Example2\" />\n"
+ "<Data:Value Key=\"3\" Name=\"Example3\" />\n"
+ "</Data:Keys>";
private static final String X2 = "<Data:Keys xmlns:Data=\"foo\">\n"
+ "<Data:Value Key=\"2\" Name=\"Example2\" />\n"
+ "<Data:Value Key=\"1\" Name=\"Example1\" />\n"
+ "<Data:Value Key=\"3\" Name=\"Example3\" />\n"
+ "</Data:Keys>";
public static void main(String[] args) {
Diff diff = DiffBuilder.compare(Input.from(X1))
.withTest(Input.from(X2))
.ignoreComments()
.ignoreWhitespace()
.normalizeWhitespace()
.checkForSimilar()
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.conditionalBuilder()
.whenElementIsNamed("Value")
.thenUse(ElementSelectors.byNameAndAttributes("Key"))
.elseUse(ElementSelectors.byName)
.build()
)).build()
;
System.err.println(diff);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment