Similar questions have been asked on this forum, but didn't the precise answer to what I am looking for.
I have a question regarding “Similar” and “Identical”. In the following example given on XMLUnit help page:
<author>DanBrown</author><category></category>
And
<category></category><author>DanBrown</author>
The output comes out to be:
Similar? true
Identical? false
***********************
Expected sequence of child nodes ’5′ but was ’7′ – comparing at /books/book/author to at /books/book/author
***********************
***********************
Expected sequence of child nodes ’7′ but was ’5′ – comparing at /books/book/category to at /books/book/category
***********************
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".
Similar ? false
Identical ? false
***********************
Expected presence of child node 'OtherSrvcName' but was 'null' - comparing <OtherSrvcName…> at /UsernameToken/OtherSrvcPref/OtherSrvcName to at null
***********************
***********************
Expected presence of child node 'null' but was 'OtherSrvcName' - comparing at null to <OtherSrvcName…> at /UsernameToken/OtherSrvcPref/OtherSrvcName
***********************
***********************
Expected presence of child node 'OtherSrvcName' but was 'null' - comparing <OtherSrvcName…> at /UsernameToken/OtherSrvcPref/OtherSrvcName to at null
***********************
***********************
Expected presence of child node 'null' but was 'OtherSrvcName' - comparing at null to <OtherSrvcName…> at /UsernameToken/OtherSrvcPref/OtherSrvcName
***********************
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As to why you get a similar ? false in you first example, I'll need to investigate it. At first glance this looks like a bug.
In the second case XMLUnit doesn't have an ordering problem per se, it is a matching problem. By default it matches on the element name only so it will compare your OtherSrvcPref elements in the order they appear inside the document - and then complain about the different nested text in their child nodes. For this you will have to override the ElementQualifier and RecursiveElementNameAndTextQualifier should work for this specific case.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Similar questions have been asked on this forum, but didn't the precise answer to what I am looking for.
I have a question regarding “Similar” and “Identical”. In the following example given on XMLUnit help page:
And
The output comes out to be:
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:
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:
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.
I don't understand this difference in the behaviour of the output? Could someone please help me out here..
Thanks.
As to why you get a similar ? false in you first example, I'll need to investigate it. At first glance this looks like a bug.
In the second case XMLUnit doesn't have an ordering problem per se, it is a matching problem. By default it matches on the element name only so it will compare your OtherSrvcPref elements in the order they appear inside the document - and then complain about the different nested text in their child nodes. For this you will have to override the ElementQualifier and RecursiveElementNameAndTextQualifier should work for this specific case.