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
0 answers

how to compare two xml files depending on a specific attribute value?

i want to know if it is possible to make xmlunit compare only nodes that have the same value of a specific attribute.. for example in make case i want xmlunit to compare nodes which have the same value of MOID ( attribute ) here is two xml files…
user771221
  • 127
  • 9
1
vote
1 answer

XMLunit Comparison failure because child nodes order

I'm comparing a generated XML file with another example using XMLunit, and Im having problems with ChildNodes Order and their attributes. (Linux and Mac generation differ) This is what I've tried: @Test public void testComparingXML() throws…
1
vote
2 answers

ignore xs:float (and other types) representation differences when comparing XML files

I am using XMLUnit for my JUnit tests and I would like to configure it so as to ignore differences related to alternative (but equivalent) rendering of certain types. E.g. 3.14 vs 3.140 for xs:float fields. I guess a full solution would require the…
Marcus Junius Brutus
  • 26,087
  • 41
  • 189
  • 331
1
vote
1 answer

XMLUnit Asserts Equal XML Are Not Equal

In my JUnit tests I compare an expected XML file to a virtual document a parser created: public void test() throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); …
Stefan S.
  • 3,950
  • 5
  • 25
  • 77
1
vote
1 answer

How to check for existence of subtree in XML document

I need to check if an XML document contains a given XML DOM subtree. I only need to ensure that all the elements and attributes from this subtree are present in the document. However, there can be more elements or attributes in the subtree of the…
livthomas
  • 1,160
  • 1
  • 14
  • 25
1
vote
3 answers

xmlunit sees differences in identical xml

I'm using xmlunit for the first time to compare 2 pieces of xml. It shows great promise but has failed at the first hurdle. It is comparing two almost identical pieces of xml and claims that they are different. Diff diff = new Diff(control,…
mdarwin
  • 1,684
  • 7
  • 28
  • 72
1
vote
1 answer

Ignore those elements that are commented out in one xml file using xmlunit

I want to compare two XML files. I am using XMLUnit to compare. I am having some problem while comparing like the following xml snippets. Expected: 405018111
Muhammad Ijaz
  • 181
  • 1
  • 4
  • 15
1
vote
1 answer

Ignore attributes XML Unit

I am comparing XML files with XMLUnit and was wondering and if an element does not exist in one of the files then all subsequent elements generate the alert of: [not identical] Expected sequence of child nodes 'X' but was 'Y'. I am wondering if…
1
vote
1 answer

How to ignore a line in xmlUnit

Hi I was wondering how I can ignore a line in XMLUnit. For instance if I had the following tag which would always be different e.g file 1: 8 file 2: 10 and the rest of the file should match, how could I do this? The sample code I was using…
1
vote
1 answer

Why those two xml string aren't similar

I have two similar xml string. I use XMLUnit to compare them but after I run some sample test to check them it says that they aren't similar and identical. I agree that they aren't identical but I think it should return true for similar. Below are…
mardok
  • 2,135
  • 2
  • 23
  • 37
1
vote
1 answer

XMLUnit ignore Order of Elements

I compare two xml files with each other with the help of XMLUnit now if i use this code to compare @Test public void testForEquality() throws Exception { String xml1 = "
"; String…
LoremIpsum
  • 505
  • 4
  • 8
  • 20
1
vote
1 answer

XML Comparison using XMLUnit

I want to compare two XML files using XMLUnit (I don't want to reinvent something which is already present). XML 1: Test 01 Test…
Sumit Sahoo
  • 2,949
  • 1
  • 25
  • 37
1
vote
1 answer

Has XMLUnit an Output of XPathes with Namespaces?

For my Java program im using XMLUnit 1.5, wich compares two XML-Files (with Namespaces). But the XPathes, I get, do not contain any Namespaces. How I can tell XMLUnit todo that? Is that possible? Here is my code: control = new…
1
vote
2 answers

XmlUnit and Child Nodes

I am using xmlunit to compare two text files. The control xml is: Angels & Demons 9971-5-0210-0 Dan Brown I am…
timmy
  • 1,752
  • 6
  • 23
  • 35
1
vote
3 answers

Java XML files comparison

I'm trying to compare 2 XML files using XMLUnit. I tried with the following code in eclipse, I have placed the xml files to be compared in the local directory. import java.io.FileNotFoundException; import java.io.IOException; import…
shockwave
  • 3,074
  • 9
  • 35
  • 60