aspose file tools*
The moose likes XML and Related Technologies and the fly likes XMLUnit: Element and Attribute ordering problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XMLUnit: Element and Attribute ordering problem" Watch "XMLUnit: Element and Attribute ordering problem" New topic
Author

XMLUnit: Element and Attribute ordering problem

Norman Meister
Greenhorn

Joined: Jul 03, 2009
Posts: 17
I have a question regarding “Similar” and “Identical”. In the following example given on XMLUnit help page:



And




The output comes out to be:

  • Similar? true
    Identical? false
    ***********************
    Expected sequence of child nodes ’5′ but was ’7′ – comparing at /books[1]/book[1]/author[1] to at /books[1]/book[1]/author[1]
    ***********************
    ***********************
    Expected sequence of child nodes ’7′ but was ’5′ – comparing at /books[1]/book[1]/category[1] to at /books[1]/book[1]/category[1]
    ***********************



  • My question how can we “NOT” include in the output such non-identical information? My problem is that I have a long xml documents to compare. There are cases, where the differences are related to orderring and in addition to others.

    But when I get the total output, it gets kind of difficult to find the actual differences (non-orderring) related.

    I have to manually skip the non-important information (orderring differences) from the actual differences for example if anything is missing in the reference documents or have different content etc.

    Have said that, I read somewhere that such "orderring" problems can be solved with my own "custom DifferenceListener".

    So I did the following, (the whole class):



    reference.xml



    comparison.xml




  • The output:

    Similar ? false
    Identical ? false



  • This to some degree resolved my original problem, but my question is why Similar is false? Shouldn't it be 'true' ?

    Secondly, on my slightly changing the XMLs, the entire output then yielded the same original response, which i am not interested in.

    reference.xml



    comparision.xml




  • Output:

    Similar ? false
    Identical ? false
    ***********************
    Expected presence of child node 'OtherSrvcName' but was 'null' - comparing <OtherSrvcName...> at /UsernameToken[1]/OtherSrvcPref[1]/OtherSrvcName[1] to at null
    ***********************
    ***********************
    Expected presence of child node 'null' but was 'OtherSrvcName' - comparing at null to <OtherSrvcName...> at /UsernameToken[1]/OtherSrvcPref[1]/OtherSrvcName[1]
    ***********************
    ***********************
    Expected presence of child node 'OtherSrvcName' but was 'null' - comparing <OtherSrvcName...> at /UsernameToken[1]/OtherSrvcPref[2]/OtherSrvcName[1] to at null
    ***********************
    ***********************
    Expected presence of child node 'null' but was 'OtherSrvcName' - comparing at null to <OtherSrvcName...> at /UsernameToken[1]/OtherSrvcPref[2]/OtherSrvcName[1]
    ***********************


  • Now why am i getting the 'Expected presence...' messages in the output? Shouldn't it just produce the same output as in the previous case, i.e.

  • Similar ? false
    Identical ? false




  • I don't understand this difference in the behaviour of the output? Could someone please help me out here..

    Thanks.
     
    jQuery in Action, 2nd edition
     
    subject: XMLUnit: Element and Attribute ordering problem
     
    Similar Threads
    Getting the arraylist through session
    How to print the tag element along with the value
    JFrame vs JInternalFrame
    How to change this java file into jsp?
    Why I can't retrieve records stored in a XMLFile correctly?