Hi Jonathan On 2010-12-14, Jonathan Foulkes wrote:
> I'm working on a project that involves producing visual diffs of XML > files. A major requirement is that elements should be able to be > re-ordered but will not display as different unless they are logically > different. I thought that XMLUnit's Diff class would accomplish this > using the similar() function, and built my application > accordingly. In general it does - as long as it compares the elements you want it to compare. Sometimes XMLUnit will need you help in order to know what is important to your comparision and this help comes by an <http://xmlunit.sourceforge.net/userguide/html/ar01s03.html#ElementQualifier> > For example, I have two blocks of XML: > <application-variable> > <name>database</name> > <protected>false</protected> > <value>SupportTracker</value> > </application-variable> > <application-variable> > <name>conserver</name> > <protected>false</protected> > <value>jonathanf-vm</value> > </application-variable> > and > <application-variable> > <name>conserver</name> > <protected>false</protected> > <value>jonathanf-vm</value> > </application-variable> > <application-variable> > <name>database</name> > <protected>false</protected> > <value>SupportTracker</value> > </application-variable> By default XMLUnit will compare the first application-variable element of either XML snippet with each other and they are identical (same name, no attributes at all, same number of children) and the dive further down the subtree rooted by this element. Of course the name elements it sees next are different. What you want XMLUnit to do is to make it realize that it has to look at the nested text of the "name" child element of the "application-variable" element when it decides which subtrees to compare. Neither of the built-in ElementQualifiers will work for you, you will have to write an implementation of your own - but that won't be too difficult. You could extend ElementNameQualifier and only intercept it if the element's local name matches application-variable to inject you own logic. Stefan ------------------------------------------------------------------------------ Lotusphere 2011 Register now for Lotusphere 2011 and learn how to connect the dots, take your collaborative environment to the next level, and enter the era of Social Business. http://p.sf.net/sfu/lotusphere-d2d _______________________________________________ Xmlunit-general mailing list Xmlunit-general@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xmlunit-general