From: SourceForge.net <no...@so...> - 2007-06-08 11:27:51
|
Bugs item #1731980, was opened at 2007-06-06 14:16 Message generated for change (Comment added) made by bodewig You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=1731980&group_id=23187 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Closed >Resolution: Invalid Priority: 5 Private: No Submitted By: Rooks (rooks_sf) Assigned to: Nobody/Anonymous (nobody) Summary: XMLUnit say indentical xmls are different Initial Comment: Consider the 2 attached xmls : They are same but for whitespaces but following code says they are different. public static boolean compareFiles(File f1, File f2) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document d1 = builder.parse(f1); DocumentBuilder builder1 = factory.newDocumentBuilder(); Document d2 = builder1.parse(f2); Diff xmlDiff = XMLUnit.compareXML(d1, d2); debug("XML Diff :: " + xmlDiff.toString()); return xmlDiff.identical() || xmlDiff.similar(); } The debug diff printed out is : XML Diff :: org.custommonkey.xmlunit.Diff [different] Expected number of child nodes '8' but was '9' - comparing <hierarchy...> at /hierarchy[1] to <hierarchy...> at /hierarchy[1] ---------------------------------------------------------------------- >Comment By: Stefan Bodewig (bodewig) Date: 2007-06-08 13:27 Message: Logged In: YES user_id=113148 Originator: NO The two files you've attached are not identical, there is an additional newline between the closing tag of namespaces and the opening one of hierarchyVersion in exportHierarchy. Whitespace between elements is significant unless you tell XMLUnit to ignore it (which is what "nobody" suggested in the previous comment). In the absence of a DTD or an XML Schema XMLUnit cannot know whether an element supports mixed content so it cannot know whether the whitespace-only text content is significant or not. The default is to assume that whitespace is significant. Since you provide a Schema, it might work if you turn on validation on your DocumentBuilder since this may suppress the whitespace node completely. I haven't tried that, though. I'm closing the bug report as invalid since XMLUnit behaves as expected. ---------------------------------------------------------------------- Comment By: Nobody/Anonymous (nobody) Date: 2007-06-08 10:34 Message: Logged In: NO Add the following line b4 u do the comparison: XMLUnit.setIgnoreWhitespace(true); ---------------------------------------------------------------------- Comment By: Rooks (rooks_sf) Date: 2007-06-06 14:19 Message: Logged In: YES user_id=1535638 Originator: YES This happens in both 1.0 and XMLUnit 1.1 beta 2. ---------------------------------------------------------------------- Comment By: Rooks (rooks_sf) Date: 2007-06-06 14:17 Message: Logged In: YES user_id=1535638 Originator: YES File Added: testExportHierarchy_Output.xml ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=1731980&group_id=23187 |