From: Naresh B. <NB...@sa...> - 2008-09-05 14:24:39
|
I have not received a response to my question below for over a month. Could someone please let me know if this is the right list or should I be posting somewhere else? XMLUnit is the best piece of software I have found for XML comparisons, and I would love to adopt it if I can get some basics out of the way. Thanks. Naresh -----Original Message----- From: Naresh Bhatia Sent: Saturday, July 26, 2008 1:27 PM To: 'xml...@li...' Subject: Matching ordered and unordered collections I am a newbie to XMLUnit. I was trying to match the following pieces of XML where 1) forums is an unordered collection for forum objects 2) forum is an unordered collection of thread objects 3) thread is an ordered collection of message objects Control ======= <forums> <forum> <name>forum1</name> <thread> <title>thread11</title> <message>msg111</message> <message>msg112</message> </thread> <thread> <title>thread12</title> <message>msg121</message> <message>msg122</message> </thread> </forum> <forum> <name>forum2</name> <thread> <title>thread21</title> <message>msg211</message> <message>msg212</message> </thread> <thread> <title>thread22</title> <message>msg221</message> <message>msg222</message> </thread> </forum> </forums> Test ==== <forums> <forum> <name>forum2</name> <thread> <title>thread22</title> <message>msg221</message> <message>msg222</message> </thread> <thread> <title>thread21</title> <message>msg211</message> <message>msg212</message> </thread> </forum> <forum> <name>forum1</name> <thread> <title>thread12</title> <message>msg121</message> <message>msg122</message> </thread> <thread> <title>thread11</title> <message>msg111</message> <message>msg112</message> </thread> </forum> </forums> 1) What is the best way to specify this in XMLUnit? Here's my attempt: Diff diff = new Diff(control, test); diff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier()); System.out.println(diff.toString()); This prints the following difference (obviously not what I want): [different] Expected text value 'forum1' but was 'forum2' - comparing <name ...>forum1</name> at /forums[1]/forum[1]/name[1]/text()[1] to <name ...>forum2</name> at /forums[1]/forum[1]/name[1]/text()[1] 2) What's interesting is that if I take out threads and messages from the data above, then diff.similar() returns true. So why does the addition of threads and messages choke at the forum level? 3) Is there a general way to specify ordered/unordered collections at different levels of nesting? I am trying to write a testing framework for my application and it would be nice to specify the matching criteria flexibly. Thanks. Naresh Bhatia |