Questions tagged [xmlunit]

XMLUnit is an open source project which enables JUnit-style assertions to be made about the content and structure of XML.

XMLUnit extends and to enable unit testing of XML.

It compares a control XML document to a test document or the result of a transformation, validates documents, and compares the results of expressions.

XMLUnit for Java

XMLUnit for Java provides two JUnit extension classes, XMLAssert and XMLTestCase, and a set of supporting classes (e.g. Diff, DetailedDiff,Transform,SimpleXpathEngine,Validator,NodeTest) that allow assertions to be made about:

  • The differences between two pieces of XML
  • The outcome of transforming a piece of XML using XSLT
  • The evaluation of an XPath expression on a piece of XML
  • The validity of a piece of XML
  • Individual nodes in a piece of XML that are exposed by DOM Traversal

XMLUnit for Java can also treat HTML content (even badly-formed HTML) as valid XML to allow these assertions to be made about the content of web pages too.

XMLUnit is available for and .

184 questions
1
vote
3 answers

Issue with setIgnoreWhitespace in XMLUnit

I'm having trouble getting xmlunit to ignore whitespace in my XML using setIgnoreWhitespace... any idea what could be wrong or what I could check? JVM: 1.6, XMLUnit 1.3, IDE: JDeveloper 11.1.1.6 For example the below returns "Expected number of…
mrcrabs
  • 141
  • 2
  • 7
1
vote
1 answer

Using RecursiveElementNameAndTextQualifier(XMLUnit)

I need to compare two XML files where both have different order of entities. 1 2
One
  • 15
  • 2
  • 7
1
vote
2 answers

Finding differences in two XML files using XMLUnit

How to check for only particular nodes and not all nodes for difference while using the DetailedDiff function of XMLUnit this is my code: public static void main(String[] args) { //URL url1 =…
Chani
  • 5,055
  • 15
  • 57
  • 92
1
vote
4 answers

XML comparison - with a slight twist

Here is the problem that I am trying to solve. I have two folders which contain XML files. One folder - lets say "source" folder - contains around 350,000 XML files. Another folder - lets say "compare" folder - contains the same 350,000 XML…
partha
  • 2,286
  • 5
  • 27
  • 37
1
vote
2 answers

Compare XML ignoring specific XPaths

I am using XML Unit to comparing two XMLs and check whether the two are similar. My requirement is - I want to ignore specific XPATHs during the comparison. How can I ignore the given XPATH from comparing as the XPATH can be any valid Xpath syntax…
sameer59
  • 97
  • 11
0
votes
1 answer

Using XMLUnit(Java) to compare XML strings containing entities

JDK 1.7.0 XMLUnit 1.3 When comparing this control XML string: String controlXml = "" + "" + " Hello World" + ""; With this test XML string: …
TchiYuan
  • 4,258
  • 5
  • 28
  • 35
0
votes
2 answers

comparing two instances of random java class to obtain differences of variables values

I need to compare two instances of the same java class and obtain the list of variables that are not equals. Let's say i have this kind of java class public class DummyClass { private String name; private String surname; [constructors,…
0
votes
1 answer

Compare XML using xmlunit when order of Attributes is different is not working

I have 2 xmls : Basically two XSD schemas
Abhi
  • 309
  • 1
  • 10
0
votes
0 answers

Example for ComparisonFormatter

It would be great if someone can guide me on using ComparisonFormatter in XMLUnit 2.x. String controlXml = "\n" + " foo\n" + " bar\n" + ""; String testXml = "\n" + " foo\n"…
Varshaa
  • 1
  • 1
0
votes
2 answers

Is there any way to compare two xml and it should ignore exact content text but it should compare content text by Data type

I have tried the below example and tried with different methods of DiffBuilder and CompareMatcher classes: import org.junit.jupiter.api.Test; import org.xmlunit.diff.DefaultNodeMatcher; import org.xmlunit.diff.ElementSelectors; import…
KB1
  • 51
  • 5
0
votes
1 answer

Need help in comparing 2 xml files using XMLUnit ignoring spaces in differences

I have a code in java comparing 2 xml files using XMLUnit. It is highlighting the differences for a extra space in one of the lines which I wish to ignore. How can I achieve this. Below are the settings…
kiran kumar
  • 35
  • 3
  • 7
0
votes
2 answers

Compare two xml files ignoring certain elements using XPath in Java

How can I compare two XML files, ignoring certain elements using XPath? For example, I need to compare the below two XML files, but I need to ignore 'Date' element, by passing the Xpath(//Set[1]/Product[\1]/Date) of this element during the run. The…
Oasis001
  • 79
  • 2
  • 17
0
votes
0 answers

Java XMLUnit not properly ignoring child order when comparing

I am trying to use Java XMLUnit to check if these two XML's are the same, ignoring order. I have tried using the Diff approach as well as using NodeMatcher but neither worked. I have tried a variety of ElementQualifiers as well. What am I missing…
nithins
  • 1
  • 1
0
votes
1 answer

Exception in thread "main" while trying to compare two xml's using XML Unit

package util; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.util.ArrayList; import…
Akshay
  • 1
  • 1
0
votes
1 answer

how to compare prefixed with no prefix xml documents in xmlunit to get similar result

xmlnit does not recognize the following two xml "identical" (except one has defined namespace) documents to be similar:
ama
  • 1,525
  • 1
  • 16
  • 34