From: Stefan B. <bo...@ap...> - 2008-09-05 14:41:12
|
sorry I ddn't respond earlier, I've been on vacation when you sent your original request and still haven't caught up with everything. Yes, this is the right forum to use. On Sat, 26 Jul 2008, Naresh Bhatia <NB...@sa...> wrote: > 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 That's a bit too much "unordered" for the built-in and custom matchers. you'd need to build your own ElementQualifier since this goes beyond what even RecursiveElementNameAndTextQualifier can do. > 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> > > 2) What's interesting is that if I take out threads and messages > from the data above, then diff.similar() returns true. The forum elements alone would qualify for the recursive qualifier, but it is restricted to elements that contains only one child that holds text. You are simply requesting more from it than it can deal with. > 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. Try to write a generic Elementqualifier that works for your case and you'll see that it is way more complex than you think. That being said, a specialized ElementQualifier would probably be easy to write (one that only looked at the forum's name and the thread's title when asked to select the best matching forum/thread. Unfortunately there is no ready-made solution. Stefan |