From: <bo...@us...> - 2008-04-04 15:12:39
|
Revision: 260 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=260&view=rev Author: bodewig Date: 2008-04-04 08:12:40 -0700 (Fri, 04 Apr 2008) Log Message: ----------- set DocumentBuilderFactory to coalescing mode when ignoring differences between CDATA and Text Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java trunk/xmlunit/src/user-guide/XMLUnit-Java.xml trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2008-03-28 16:14:21 UTC (rev 259) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2008-04-04 15:12:40 UTC (rev 260) @@ -666,9 +666,16 @@ * Whether CDATA sections and Text nodes should be considered the same. * * <p>The default is false.</p> + * + * <p>This also set the DocumentBuilderFactory's {@link + * javax.xml.parsers.DocumentBuilderFactory#setCoalescing + * coalescing} flag on the factories for the control and test + * document.</p> */ public static void setIgnoreDiffBetweenTextAndCDATA(boolean b) { ignoreDiffBetweenTextAndCDATA = b; + getControlDocumentBuilderFactory().setCoalescing(b); + getTestDocumentBuilderFactory().setCoalescing(b); } /** Modified: trunk/xmlunit/src/user-guide/XMLUnit-Java.xml =================================================================== --- trunk/xmlunit/src/user-guide/XMLUnit-Java.xml 2008-03-28 16:14:21 UTC (rev 259) +++ trunk/xmlunit/src/user-guide/XMLUnit-Java.xml 2008-04-04 15:12:40 UTC (rev 260) @@ -3410,6 +3410,16 @@ kind of difference) the XPath for the "missing" node will be null. It used to be some random XPath of a different node. </listitem> + + <listitem> + <literal>XMLUnit.setsetIgnoreDiffBetweenTextAndCDATA</literal> + now also + sets <literal>DocumentBuilderFactory.setCoalescing</literal>. + This has been done so that whitespace differences can be + resolved according to the corresponding flags even in the + presence of CDATA + sections. <ulink href="https://sourceforge.net/tracker/index.php?func=detail&aid=1903923&group_id=23187&atid=377768">Issue + 1903923</ulink>.</listitem> </itemizedlist> </section> Modified: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java 2008-03-28 16:14:21 UTC (rev 259) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java 2008-04-04 15:12:40 UTC (rev 260) @@ -843,4 +843,28 @@ assertEquals(12, count[0]); } + public void testCDATAAndIgnoreWhitespace() throws Exception { + String control = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + + "<Data><Person><Name><![CDATA[JOE]]></Name></Person></Data>"; + + String test = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + +"<Data>" + +" <Person>" + +" <Name>" + +" <![CDATA[JOE]]>" + +" </Name>" + +" </Person>" + +"</Data>"; + + XMLUnit.setIgnoreWhitespace(true); + XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); + try { + Diff diff = buildDiff(control, test); + assertTrue(diff.toString(), diff.similar()); + } finally { + XMLUnit.setIgnoreWhitespace(false); + XMLUnit.setIgnoreDiffBetweenTextAndCDATA(false); + } + } } + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |