This code:
import org.custommonkey.xmlunit.Diff;
String result = "<ns1:Square xsi:type=\"ns1:Shape\" xmlns:ns1=\"http://example.com/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>";
String correct = "<ns2:Square xsi:type=\"ns2:Shape\" xmlns:ns2=\"http://example.com/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>";
Diff diff = new Diff(result, correct);
System.out.println("diff:" + diff);
System.out.println("diff.similar(): " + diff.similar());
results in:
diff: org.custommonkey.xmlunit.Diff
[not identical] Expected namespace prefix 'ns1' but was 'ns2' - comparing <ns1:Square...> at /Square[1] to <ns2:Square...> at /Square[1]
[different] Expected attribute value 'ns1:Shape' but was 'ns2:Shape' - comparing <ns1:Square xsi:type="ns1:Shape"...> at /Square[1]/@type to <ns2:Square xsi:type="ns2:Shape"...> at /Square[1]/@type
diff.similar(): false
---
someone posted a fix here:
http://stackoverflow.com/questions/14647861/xmlunit-diff-returns-similar-false-if-there-is-a-xsitype-and-a-different-namesp/14648786#14648786
Actually, XMLUnit doesn't really support much of the XML-Schema Instance stuff at all.
I've started to fix it in the 1.x branch and simply ignoring the namespace prefix is trivial for this case, making sure the prefixes map to the same NS uris seems more difficult, at least as long as I'm in Java 1.4 land.
Once this is fixed I'll roll a new release.
This should be fixed with svn revision 502 in the 1.x Branch https://xmlunit.svn.sourceforge.net/svnroot/xmlunit/branches/xmlunit-1.x
Can you try to build it yourself to see whether it works for you?
Before I cut a new release I want to look around the Schema Instance namespace to see whether there is anything else XMLUnit could support in a better way.
The only remaining xsi-attribute is xsi:nil which - I think - is handled reasonably.
I'm preparing a new release, would be good if you could test the fix before I finalize it. If you have any trouble building XMLUnit from source, I'll be happy to provide a binary.
Hi,
I tried your last revision, 517, and it works correctly!
for the case i reported, and other cases also.
please let me now about your new release.
regards,
David
XMLUnit for Java 1.4 has just been released. It hasn't made its way to Maven central, yet, but that's just a matter of time.
Hi, I confirm that version 1.4 has made its way to maven central,
and that it solves the problem for the case i reported, and other cases also.
thanks,
david