On 2009-12-15, Dubey, Tarun <[email protected]> wrote:

> The following test case fails while according to the javadocs of
> similar() method in Diff this should pass

>     @Test
>     public void testXmlIgnoreOrder() throws IOException, SAXException {
>         XMLUnit.setIgnoreWhitespace(true);
>         XMLUnit.setIgnoreAttributeOrder(true);
>         String xml1 =
>                 "<TEST><FLIGHT NUM=\"121\"></FLIGHT><FLIGHT
> NUM=\"122\"></FLIGHT></TEST>";

>         String xml2 =
>                 "<TEST><FLIGHT NUM=\"122\"></FLIGHT><FLIGHT
> NUM=\"121\"></FLIGHT></TEST>";
>         Diff diff = XMLUnit.compareXML(xml1, xml2);
>         Assert.assertTrue(diff.similar());
>     }

No, it should fail.  IgnoreAttributeOrder affects whether the order of
attributes of a single element is significant.  All your elements only
have a single attribute, so order of them is the same anyway.

What is different is the order of elements.

If the order of elements is not significant to you, you'll have to help
XMLUnit decide which elements to compare by overriding the
ElementQualifier.  The default implementations only looks at element
names, if the names are the same, it will compare the elements.

> Surprisingly the same test passes if the element names are different as
> shown below

>                 "<TEST><FLIGHT NUM=\"121\"></FLIGHT><CRUISE
> NUM=\"122\"></CRUISE></TEST>";

Yes.  If the names are different, the FLIGHT elements and the CRUISE
elements get matched against each other.  If they are the same, XMLUnit
will match them in the order they occur.

You want to use an ElementNameAndAttributeQualifier
<http://xmlunit.sourceforge.net/userguide/html/ar01s03.html#ElementNameAndAttributeQualifier>

Stefan

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Xmlunit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xmlunit-general

Reply via email to