From: <bo...@us...> - 2008-04-04 15:46:06
|
Revision: 261 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=261&view=rev Author: bodewig Date: 2008-04-04 08:46:09 -0700 (Fri, 04 Apr 2008) Log Message: ----------- Add flag that controls the parser's entity expansion 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-04-04 15:12:40 UTC (rev 260) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2008-04-04 15:46:09 UTC (rev 261) @@ -82,6 +82,7 @@ private static boolean ignoreAttributeOrder = false; private static String xsltVersion = "1.0"; private static String xpathFactoryName = null; + private static boolean expandEntities = false; private static final String XSLT_VERSION_START = " version=\""; private static final String XSLT_VERSION_END = "\">"; @@ -850,5 +851,25 @@ return XSLTConstants.XSLT_START_NO_VERSION + XSLT_VERSION_START + getXSLTVersion() + XSLT_VERSION_END; } + + /** + * Whether the parser shall be instructed to expand entity references. + * + * <p>Defaults to false.</p> + * + * @see javax.xml.parsers.DocumentBuilderFactory#setExpandEntityReferences + */ + public static void setExpandEntityReferences(boolean b) { + expandEntities = b; + getControlDocumentBuilderFactory().setExpandEntityReferences(b); + getTestDocumentBuilderFactory().setExpandEntityReferences(b); + } + + /** + * Whether the parser shall be instructed to expand entity references. + */ + public static boolean getExpandEntityReferences() { + return expandEntities; + } } Modified: trunk/xmlunit/src/user-guide/XMLUnit-Java.xml =================================================================== --- trunk/xmlunit/src/user-guide/XMLUnit-Java.xml 2008-04-04 15:12:40 UTC (rev 260) +++ trunk/xmlunit/src/user-guide/XMLUnit-Java.xml 2008-04-04 15:46:09 UTC (rev 261) @@ -2354,6 +2354,15 @@ </programlisting> </section> + <section id="Entity Reference Expansion"> + <title>Entity Reference Expansion</title> + + <para>Normally the XML parser will expand character references + to their Unicode equivalents but for more complex entity + definitions the parser may expand them or not. + Using <literal>XMLUnit.setExpandEntityReferences</literal> you + can control the parser's setting.</para> + </section> </section> </section> @@ -3455,6 +3464,13 @@ <xref linkend="MatchTracker"/>. <ulink url="https://sourceforge.net/tracker/index.php?func=detail&aid=1860491&group_id=23187&atid=377771">Issue 1860491</ulink>.</listitem> + <listitem>It is now possible to have more control over + whether the parser expand entity references or not by + using <literal>XMLUnit.setExpandEntityReferences</literal>, + see <xref linkend="Entity Reference + Expansion"/>. <ulink href="https://sourceforge.net/tracker/index.php?func=detail&aid=1877458&group_id=23187&atid=377771">Issue + 1877458</ulink>.</listitem> + <listitem>New examples have been added: <itemizedlist> <listitem><literal>RecursiveElementNameAndTextQualifier</literal> Modified: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java 2008-04-04 15:12:40 UTC (rev 260) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java 2008-04-04 15:46:09 UTC (rev 261) @@ -866,5 +866,21 @@ XMLUnit.setIgnoreDiffBetweenTextAndCDATA(false); } } + + /** + * Not a real test. Need something that actually fails unless I + * set the flag. + */ + public void testEntityExpansion() throws Exception { + String control = "<root>bla bla</root>"; + String test = "<root>bla
bla</root>"; + //XMLUnit.setExpandEntityReferences(true); + try { + Diff diff = buildDiff(control, test); + assertTrue(diff.toString(), diff.similar()); + } finally { + XMLUnit.setExpandEntityReferences(false); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |