Does XMLUnit have an assert to ignore whitespace

Scott picture Scott · Apr 19, 2011 · Viewed 10.1k times · Source

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 = "<msg><uuid>0x00435A8C</uuid></msg>";
 String myTestXML = "<msg><uuid>0x00435A8C</uuid>      </msg>";
 assertXMLEqual(myControlXML, myTestXML);
 Diff diff = new Diff(myControlXML, myTestXML);
 assertTrue(diff.similar());
}

Answer

Kai Sternad picture Kai Sternad · Apr 19, 2011

Yes, XMLUnit can ignore whitespaces. See API documentation for details. You can enable it by setting:

XMLUnit.setIgnoreWhitespace(true)