From: SourceForge.net <no...@so...> - 2010-02-05 11:56:10
|
Bugs item #2946497, was opened at 2010-02-05 11:56 Message generated for change (Tracker Item Submitted) made by You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=2946497&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: Java 1.2 Status: Open Resolution: None Priority: 5 Private: No Submitted By: https://www.google.com/accounts () Assigned to: Nobody/Anonymous (nobody) Summary: Error for xmls with different child & attr sequence Initial Comment: I have two xmls XML 1 <root> <Override ContentType="slideLayout+xml" PartName="slideLayout1.xml" /> <Override ContentType="slideLayout+xml" PartName="slideLayout8.xml" /> <Override ContentType="slideLayout+xml" PartName="slideLayout7.xml" /> </root> XML 2 <root> <Override ContentType="slideLayout+xml" PartName="slideLayout8.xml" /> <Override ContentType="slideLayout+xml" PartName="slideLayout1.xml" /> <Override ContentType="slideLayout+xml" PartName="slideLayout7.xml" /> </root> XML 3 <root> <Override PartName="slideLayout8.xml" ContentType="slideLayout+xml" /> <Override PartName="slideLayout1.xml" ContentType="slideLayout+xml" /> <Override PartName="slideLayout7.xml" ContentType="slideLayout+xml" /> </root> Accordingly to me all the xmls are equal. I tried using TestCase.java (attached here) to compare them. I tried to compare these two xmls ignoring both the child sequence as well as the attribute sequence, but xml unit still complains they are different. Here is the source code I tried, please let me know what changes do I do my source in order to make XMLUnit say the three xml files are equal. import java.io.IOException; import java.util.List; import org.custommonkey.xmlunit.DetailedDiff; import org.custommonkey.xmlunit.Difference; import org.custommonkey.xmlunit.DifferenceConstants; import org.custommonkey.xmlunit.DifferenceListener; import org.custommonkey.xmlunit.XMLTestCase; import org.w3c.dom.Node; import org.xml.sax.SAXException; /** * @author rohitghatol * */ public class TestCase extends XMLTestCase { public static final String TAB = " "; private static final String leftSnippet = "<root><Override ContentType=\"slideLayout+xml\" PartName=\"slideLayout1.xml\" /> <Override ContentType=\"slideLayout+xml\" PartName=\"slideLayout8.xml\" /> <Override ContentType=\"slideLayout+xml\" PartName=\"slideLayout7.xml\" /> </root>"; private static final String rightSnippet = "<root><Override ContentType=\"slideLayout+xml\" PartName=\"slideLayout8.xml\" /> <Override ContentType=\"slideLayout+xml\" PartName=\"slideLayout1.xml\" /> <Override ContentType=\"slideLayout+xml\" PartName=\"slideLayout7.xml\" /> </root>"; public void compareString(final String leftContent, final String rightContent) throws SAXException, IOException { final DetailedDiff myDiff = new DetailedDiff(compareXML(leftContent, rightContent)); myDiff.overrideDifferenceListener(new NoSequenceDifferenceListener()); final List<Difference> allDifferences = myDiff.getAllDifferences(); if ( (null == allDifferences) || (allDifferences.size() <= 0) ) { System.out.println(TAB + "No Difference found"); } else { System.out.println(TAB + allDifferences.size() + " number of difference found"); } int index = 0; for ( final Difference diff : allDifferences ) { System.out.println(TAB + ":" + (index++) + ": Difference = " + diff); } System.out.println("======================================================="); } private class NoSequenceDifferenceListener implements DifferenceListener { /* * (non-Javadoc) * @see org.custommonkey.xmlunit.DifferenceListener#differenceFound(org.custommonkey.xmlunit.Difference) */ @Override public int differenceFound(final Difference diff) { int returnVal = DifferenceListener.RETURN_UPGRADE_DIFFERENCE_NODES_DIFFERENT; switch ( diff.getId() ) { case DifferenceConstants.ATTR_SEQUENCE_ID: case DifferenceConstants.CHILD_NODELIST_SEQUENCE_ID: returnVal = DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; break; default: returnVal = DifferenceListener.RETURN_UPGRADE_DIFFERENCE_NODES_DIFFERENT; } return returnVal; } /* * (non-Javadoc) * @see org.custommonkey.xmlunit.DifferenceListener#skippedComparison(org.w3c.dom.Node, org.w3c.dom.Node) */ @Override public void skippedComparison(final Node node1, final Node node2) { System.out.println("---> node1 " + node1.getLocalName()); } } public static void main(final String[] args) throws SAXException, IOException { final TestCase testcase = new TestCase(); testcase.compareString(leftSnippet, rightSnippet); } } ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=2946497&group_id=23187 |