Forum Discussion

awhawh's avatar
awhawh
Contributor
7 years ago
Solved

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

 

 

 

  • 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

     

7 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    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.

    • awhawh's avatar
      awhawh
      Contributor

      Thanks for your reply

       

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

  • cunderw's avatar
    cunderw
    Community Hero

    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?

      • HarnekSandhu's avatar
        HarnekSandhu
        Occasional Contributor

        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