From: Stefan B. <bo...@ap...> - 2010-04-15 04:22:22
|
On 2010-04-14, Sneha Teckchandani <sne...@gm...> wrote: > FYI - I had posted the same query to the mailing list as well. Now > marking this email to it too. You are not subscribed to the list so your mails end up in the moderation queue and I simply didn't recognize it between all the SPAM that the list receives (about one legitimate email is hidden between several hundred SPAM messages, the list receives about ten SPAM messages each day). > Due to the lack of XMLUnit awareness around me, i turn to you for a > detailed discussion. That's what we are here for. 8-) > I would like to records of my XMLs being compared instead of Line by > Line comaprison (records with unique identifiers). We used the > ElementNameQualifier Interface, did override it but it did not bring > about record comparison. > <Code> ElementQualifier overriden. > public boolean qualifyForComparison(Element arg0, Element arg1) > { > try > { > if (arg0.getNodeName() != null > && arg0.getNodeName().equals("POI")) /*Record Identifier is > the firstChild Node of teh Elelment POI and hence item(0)*/ > { > if(arg0.getChildNodes().item(0).getTextContent() > .equals(arg1.getChildNodes().item(0).getTextContent())) > return true; > else > return false; > } > } > catch (Throwable t)//TODO add asserts > { > return false; > } > return true; > } > <code> OK, let me see. You expect documents like <container> <POI ...> <some-element-name>ID1</some-element-name> </POI> <POI ...> <some-element-name>ID2</some-element-name> </POI> </container> and want to compare elements with matching IDs, right? In general I'd expect RecursiveElementNameAndTextQualifier to work here, so I may be missing a detail. Your code assumes that calling getChildNodes().item(0) on a POI element will return the Node corresponding to the element some-element-name - is this true? In my snippet above you'd likely first get a Text child node containing a linebreak and four spaces. You probably should make XMLUnit and your ElementQualifier ignore whitespace. Can you provide example snippets of real XML documents you are trying to compare? Stefan |