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
41
votes
5 answers

How do I ignore certain elements when comparing XML?

I have an XML message like so: something something else yet another thing I want to compare a message of this type produced by a method under test to an expected…
Paul Morie
  • 15,528
  • 9
  • 52
  • 57
32
votes
9 answers

Compare two XML strings ignoring element order

Suppose I have two xml strings a b b a How to write a test that compares those two strings and ignores the element order? I want the test to be as short as…
Roay Spol
  • 1,188
  • 1
  • 11
  • 17
31
votes
2 answers

Does XMLUnit have an assert to ignore whitespace

I want to compare two xml strings in a test, but the test keeps failing due to whitespace. @Test public void testForEquality() throws Exception { String myControlXML = "0x00435A8C"; String myTestXML =…
Scott
  • 2,248
  • 3
  • 22
  • 24
15
votes
2 answers

XMLUnit - Xml file indentation impacts on comparison

I am currently trying to use the XMLUnit library to compare two XML files. One of them, the candidate, is generated by my code from Java Objects (using JAXB) and the other one is the reference (I cannot modify it). Basically I am trying to prove…
reef
  • 1,813
  • 2
  • 23
  • 36
15
votes
5 answers

Are there any alternatives to XmlUnit?

I need to diff large directory structures containing generated .xml and .wsdl files. The generated .xml files differ in the order that child elements appear. The XmlUnit Diff.similar() method is supposed to handle this case: 'Two documents are…
Dean Schulze
  • 9,633
  • 24
  • 100
  • 165
10
votes
2 answers

Compare XML ignoring element order

With XMLUnit 2 how do you compare two documents without taking the element order into account? I got this question for XMLUnit 1, but apparently the new API in v2 doesn't have the mentioned method anymore. This is my current code: Diff diff =…
Imperative
  • 3,138
  • 2
  • 25
  • 40
9
votes
2 answers

XMLUnit - Ignoring 'id' attribute in comparison

I am currently working with XMLUnit and I am wondering if there is way to configure it to ignore only the id attribute of the tags I want to compare. Thanks in advance for your help.
reef
  • 1,813
  • 2
  • 23
  • 36
9
votes
1 answer

XMLUnit - Compare two XML ignoring the child order

I am trying to see if I could use XMLUnit to compare the following two different XML. I used the Diff class to compare the following two XML and checking for similar returns false. XML One
user320587
  • 1,347
  • 7
  • 29
  • 57
9
votes
3 answers

How to compare two xml with the same namespace but different prefixes using java and xmlunit

I have 2 xml files: The problem is in attributes prefixes. Some text Some text these two xml…
Constantine Gladky
  • 1,245
  • 6
  • 27
  • 45
8
votes
4 answers

.net Xml comparer for UnitTesting

I have a few unit tests where I need to make sure that XML generated by a method contains the same elements/values as an expected Xml document. I used xmlunit in Java, and although they have a .net version it doesn't seem to support namespaces. Are…
8
votes
6 answers

XMLUnit for C++

Does anyone know if there exists something like XMLUnit for C++? I'm looking for an easy way to check nodes, values, etc in a XML output. We are using Google test in Visual Studio but I suppose any library that makes the work easier will be…
Jordi
8
votes
1 answer

JDOM Is using too much memory

I have an application that uses XmlUnit to get differences from two XML files. But the problem is that XmlUnit uses JDOM. My xml Files are ~1GB big! It take too much RAM to store those xml in a JDOM document. I have tried to use SlimJDOMFactory…
JajaDrinker
  • 652
  • 6
  • 15
6
votes
3 answers

Comparing similar xml files with XmlUnit with unordered tags (same tag name with different attributes)

I am trying successfully XmlUnit, and is very helpful in my job. Now, I have a little problem, that I don't know how to solve. I have a java class, that has a Set, and when transforming it into XML, the elements inside can have any order. When I try…
greuze
  • 4,250
  • 5
  • 43
  • 62
5
votes
1 answer

How to ignore XML declaration differences with XmlUnit?

How can I configure XmlUnit.Net to ignore the XML declaration when comparing two documents? Assume I have the following control document: 1 Which I want to compare with:
RMo
  • 132
  • 7
5
votes
0 answers

Compare two xml and find the missing node using Java

This has been bothering me for days. I just need to find out what are the missing nodes in the second xml by comparison. I tried xmlunit but it doesn't really help me find the missing node since it compares line by line. two sample xml…
1
2 3
12 13