Ask a Question

aqFile.Compare not matching XML files even though they are the same

SOLVED
awhawh
Contributor

aqFile.Compare not matching XML files even though they are the same

Hi,

 

I've been using the aqFile.Compare method to compare the contents of two XML files (one that gets generated by Crystal reports) and another pre-validated XML report.

 

I've had instances when tests have failed where the method returns a error stating the XML files are different even though I have used Notepad++ to check for differences and there are none (I've attached the sample files).

 

Does anyone know whether there any differences that the method checks for that's no visible within the file?

 

Thanks

 

Adam

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
HarnekSandhu
Occasional Contributor

Re: aqFile.Compare not matching XML files even though they are the same

The files are the same and also do differ - the context is important.

 

If you compare byte by byte, i.e. a binary compare, they are one byte different in size. There is an additional non visible character after the "NINO" string:

 

</Text>
<Text Name="Text20"><TextValue>NINO
</TextValue>

 

This is 0x0D and the other is 0x0D 0x0A - very common issue with different line endings. The size differs and that is enough to fail a binary compare. See image

 

Contextually, if you look at them as XML files and look at the content in that context, the relevant content is equal.

I suspect you need to do a line by line comparison but even that is not a true XML context sensitive comparison as different formatting may throw the compariosn off.. A proper comparison would be to parse the XML file with an appropriate driver or library and compare in the true context.

 

Hope that helps.

 

Harnek

 

View solution in original post

7 REPLIES 7
tristaanogre
Community Hero

Re: aqFile.Compare not matching XML files even though they are the same

It does a byte by byte character check.  So, there are several possibilities.

 

1) File encoding may be different.  While they are XML, they are, technically, still text files... possibly encoded differently (ANSI versus UTF-8 etc).

2) Non-printing characters may be different between the two.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
awhawh
Contributor

Re: aqFile.Compare not matching XML files even though they are the same

Thanks for your reply

 

The pre validated was generated by Crystal reports as I suppose it must be the non-printing characters?

cunderw
Community Hero

Re: aqFile.Compare not matching XML files even though they are the same

I just ran the compare against these two files and they passed. 

 

aqFile.Compare("C:\\Users\\cunderwoo6\\Downloads\\NewFile.xml","C:\\Users\\cunderwoo6\\Downloads\\PreValidatedFile.xml")

Do you have example files that do not pass?


Thanks,
Carson

Click the Accept as Solution button if my answer has helped
awhawh
Contributor

Re: aqFile.Compare not matching XML files even though they are the same

I've enclosed two files which don't work (though I must admit I thought the other two didn't work)

 

Thanks

HarnekSandhu
Occasional Contributor

Re: aqFile.Compare not matching XML files even though they are the same

The files are the same and also do differ - the context is important.

 

If you compare byte by byte, i.e. a binary compare, they are one byte different in size. There is an additional non visible character after the "NINO" string:

 

</Text>
<Text Name="Text20"><TextValue>NINO
</TextValue>

 

This is 0x0D and the other is 0x0D 0x0A - very common issue with different line endings. The size differs and that is enough to fail a binary compare. See image

 

Contextually, if you look at them as XML files and look at the content in that context, the relevant content is equal.

I suspect you need to do a line by line comparison but even that is not a true XML context sensitive comparison as different formatting may throw the compariosn off.. A proper comparison would be to parse the XML file with an appropriate driver or library and compare in the true context.

 

Hope that helps.

 

Harnek

 

View solution in original post

awhawh
Contributor

Re: aqFile.Compare not matching XML files even though they are the same

Thanks Harnek

 

Out of interest ,would I get the same problem if I was comparing two .xls files? I ask this because I can save the reports in different formats

 

Adam

HarnekSandhu
Occasional Contributor

Re: aqFile.Compare not matching XML files even though they are the same

If you are comparing two .xls files with aqFile.compare, you will have even less luck as there is additional meta data stored which can be different even if the two files have identical content.

 

Do a search on this forum and I believe there is some script available that shows how to compare .xls files.

 

Harnek

cancel
Showing results for 
Search instead for 
Did you mean: