From: <mar...@ne...> - 2003-10-17 02:38:41
|
Hi, I have come across a situation where a String.equals() comparison of two xml strings returns true (ie the two xml strings are identical), yet XML Unit Diff thinks the two xml strings are different. Could this be considered a bug in Diff ?? I am using XMLUnit version 1.0 with Saxon 7.6, and have included an example of the problem in the code shown below. Any help would be appreciated. Regards, Mark. The code below, produced the following output: test: [junit] Running DiffExampleTest [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 1.313 sec [junit] Testsuite: DiffExampleTest [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 1.313 sec [junit] ------------- Standard Output --------------- [junit] ===== start string comparison ===== [junit] The strings resultTrans and myExpectedOutputXML are IDENTICAL [junit] ===== start Diff comparison ===== [junit] myDiff.identical()=false [junit] myDiff.similar()=false [junit] differences are: org.custommonkey.xmlunit.Diff [junit] [different] Expected number of child nodes '1' but was '3' - comparing <sql:query...> at /book[1]/chapter[1]/section[1]/para[1]/execute-query[1]/query[1] to <sql:query...> at /book[1]/chapter[1]/section[1]/para[1]/execute-query[1]/query[1] Below is the code: import java.io.File; import junit.framework.*; import org.custommonkey.xmlunit.*; public class DiffExampleTest extends XMLTestCase { private String myInputXML; private String myExpectedOutputXML; private String myStylesheet; public DiffExampleTest(String name) { super(name); } protected void setUp() { myInputXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<book>" + "<chapter id=\"ch1\"><title>BIO304</title>" + "<section id=\"s1\"><title>Introduction</title>" + "<para>" + "<database name=\"intro_para\" xmlns=\"http://abc.xyz.com/1.0\"/>" + "</para>" + "</section>" + "</chapter>" + "</book>"; myExpectedOutputXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<book>" + "<chapter id=\"ch1\"><title>BIO304</title>" + "<section id=\"s1\"><title>Introduction</title>" + "<para>" + "<sql:execute-query xmlns:sql=\"http://apache.org/cocoon/SQL/2.0\"><sql:query>select clobdata from content where cohort='aa'</sql:query></sql:execute-query>" + "</para>" + "</section>" + "</chapter>" + "</book>"; myStylesheet = "<?xml version=\"1.0\"?>" + "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\"" + " xmlns:logic=\"http://abc.xyz.com/1.0\">" + " <xsl:output method=\"xml\" indent=\"no\"/>" + " <xsl:param name=\"cohort\" select=\"'aa'\"/>" + " <!-- match ever thing -->" + " <xsl:template match=\"@*|node()\">" + " <xsl:copy>" + " <xsl:apply-templates select=\"@*|node()\"/>" + " </xsl:copy>" + " </xsl:template>" + " <!-- remove database tag and replace with sqlTransformer query tags -->" + " <xsl:template match=\"logic:*\">" + " <xsl:element name=\"sql:execute-query\" namespace=\"http://apache.org/cocoon/SQL/2.0\">" + " <xsl:element name=\"sql:query\" namespace=\"http://apache.org/cocoon/SQL/2.0\">select clobdata from content where cohort='<xsl:value-of select=\"$cohort\"/>'</xsl:element>" + " </xsl:element>" + " </xsl:template>" + "</xsl:stylesheet>"; } /** * Demonstrate that the string Transform.getResultString() * is idential to the string myExpectedOutputXML using the * String.equals() method. * * Demonstrate that Diff thinks the xml is different * * Check Standard Out to see the results */ public void testXSLTransform() throws Exception { // // Compare xml using string equal method // System.out.println("===== start string comparison ====="); Transform resultTransform = new Transform( myInputXML, myStylesheet); if ( myExpectedOutputXML.equals(resultTransform.getResultString())) { System.out.println("The strings resultTrans and myExpectedOutputXML are IDENTICAL"); } else { System.out.println("The strings resultTrans and myExpectedOutputXML are DIFFERENT"); } // // Compare xml using Diff // System.out.println("===== start Diff comparison ====="); Transform myTransform = new Transform( myInputXML, myStylesheet); Diff myDiff = new Diff(myExpectedOutputXML, myTransform); System.out.println("myDiff.identical()=" + myDiff.identical()); System.out.println("myDiff.similar()=" + myDiff.similar()); System.out.println("differences are: " + myDiff.toString()); } // end method } // end class __________________________________________________________________ McAfee VirusScan Online from the Netscape Network. Comprehensive protection for your entire computer. Get your free trial today! http://channels.netscape.com/ns/computing/mcafee/index.jsp?promo=393397 Get AOL Instant Messenger 5.1 free of charge. Download Now! http://aim.aol.com/aimnew/Aim/register.adp?promo=380455 |