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
2
votes
1 answer

XMLUNIT ignore xmlns?

Try to get this two XML like similar (want to ignore xmlns) and differer element sequance but not working correctly for me. If remove xmlns, doc are simmilr. I am Using XMlUnit 1.5 String s1 = "" …
TNN
  • 426
  • 2
  • 6
  • 15
2
votes
1 answer

Diff just tags of XML with XMLUnit (no text or attributes)

I'm trying to use XMLUnit to diff just the overall structure (no text/attributes) of two XML documents as follows with XMLUnit: private static final String XML_HEADER = "\n"; xhtml1 = XML_HEADER +…
aftrumpet
  • 1,189
  • 2
  • 16
  • 28
2
votes
1 answer

SoapUI log.info opens dialogue box for some reason when comparing two xml files and logging the differences

For some reason the following script when executed, prints the output not only in the log but also in an information pop-up dialogue box. Can someone explain to me why this occurs and how I can prevent it from happening? import…
MKhowaja
  • 62
  • 1
  • 10
2
votes
1 answer

XMLUnit: Unable to attach custom DifferenceListener using overrideDifferenceListener

I am unable to attach custom diff listener using overrideDifferenceListener method. String xml1 = readFile("data/xml1.xml", Charset.defaultCharset()); String xml2 = readFile("data/xml2.xml", Charset.defaultCharset()); Diff xmlDiff = new…
Red Ant
  • 315
  • 4
  • 17
2
votes
2 answers

XmlUnit: The entity "nbsp" was referenced, but not declared

I need to test a XHTML code like
 
using XmlUnit. The Diff constructor tells me this: org.xml.sax.SAXParseException: The entity "nbsp" was referenced, but not declared. I know that nbsp entity is not defined in XML, but the HTML…
Richard
  • 279
  • 2
  • 9
2
votes
2 answers

Unit testing conditional comments

I'm using XMLUnit (org.custommonkey.xmlunit.Diff) to test two HTML strings: one is produced by templating engine, other is from a static file. It works fine, but I ran to following problem: There are conditional comments in my code, like this: …
Richard
  • 279
  • 2
  • 9
2
votes
2 answers

What is the easiest way to check that one XML file is a "subset" of the second XML?

I have two XML files. The first XML has a bunch of nodes that should be present in second XML as well. The second XML might have a few extra nodes as well. I need a Java based program that can automate this check - i.e. it should tell me that given…
partha
  • 2,286
  • 5
  • 27
  • 37
2
votes
1 answer

Validating order of XML elements using XMLUnit

I need to validate order of my output xml against a XSD using XMLUnit framework. I am new to XMLUnit and have no idea how to do it. I know that XMLUnit compares two XMLs but how to compare XML against a XSD?
Himanshu Yadav
  • 13,315
  • 46
  • 162
  • 291
1
vote
1 answer

Is there a Ruby equivalent of XMLUnit?

Is there a Ruby equivalent of XMLUnit? If not, would running XMLUnit via JRuby be a viable way to use XUnit in a Ruby programme?
user82216
1
vote
0 answers

XML comparison with XMLUnit not working in specific scenario where list has different complex element and ordering

I have below XMLs with list of Customers and each Customer has list of transactions. I have managed to write XMLUnit code to ignore the order of Customers but not the transactions. The transactions have bit of unique structure(which cannot be…
Rob Wilkinson
  • 1,131
  • 5
  • 18
  • 34
1
vote
0 answers

XMLUnit comparison is not working if namespace details are included in the root element

I am trying to compare two XMLs which has the same data but in different order. When root element has no namespace and other attributes the comparison works fine. It says both are identical. However when I include namespace details it is complaining…
Rob Wilkinson
  • 1,131
  • 5
  • 18
  • 34
1
vote
0 answers

xmlunit comparisonformatter was not replaced

I have the following code for compare: Diff diff = DiffBuilder.Compare(sourceFromPath1) .WithTest(sourceFromPath2) .WithAttributeFilter(attrItem => attributesToIgnore.All(attrNameToIgnore => attrItem.Name !=…
lm.
  • 4,033
  • 4
  • 25
  • 37
1
vote
1 answer

Using XMLUnit to compare two similar xml documents ignoring node text values

I have two different XML documents below and please note that they are having the same basic structure (schema). Source XML String String Test XML Test
NoName
  • 877
  • 12
  • 28
1
vote
0 answers

How to use XMLUnit DiffBuilder to detect differences in attributes and lists of elements

I need to compare two XML strings, where there is potentially changes to arbitrary attributes within a tag, as well as tags arbitrarily inserted into, or deleted from, a sequence of tags. I have found that if I use ElementSelectors.byNameAndText I…
shifflettd
  • 43
  • 6
1
vote
1 answer

XMLUNIT 2 using comparison with ignore element order with diffbuilder and namespaces fails

I am trying to use DiffBuilder to ignore XML elements order when comparing two .xml files but it fails. I have tried every possible combination and read many articles before posting this question. For example:
MagiciaN
  • 65
  • 9