Results 1 to 5 of 5

Thread: Compare two XML files

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2004
    Posts
    48

    Compare two XML files

    Hi there!

    Does anyone know how to compare two xml files?

    what i wanna do is compare the two xml Files and then display the difference to the datagrid...thanks in advance.

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    You could probably get away with writing XSL that would be the envy of your peers:
    VB Code:
    1. <?xml version='1.0'?>
    2.  
    3. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    4.    <xsl:output method="xml"/>
    5.  
    6. <xsl:variable name="doc-file">[url]http://mymachine.com/changed.xml[/url]</xsl:variable>
    7.  
    8. <!-- copy everything that has no other pattern defined -->
    9. <xsl:template match="* | @*">
    10.    <xsl:copy><xsl:copy-of select="@*"/><xsl:apply-templates/></xsl:copy>
    11. </xsl:template>
    12.  
    13. <!-- check for every <address> element if an updated one exists -->
    14. <xsl:template match="//address">
    15.    <xsl:param name="addresseeName">
    16.       <xsl:value-of select="addressee"/>
    17.    </xsl:param>
    18.  
    19.    <xsl:choose>
    20.       <xsl:when test="document($doc-file)//addressee[text()=$addresseeName]">
    21.          <xsl:copy-of select="document($doc-file)//address[child::addressee[text()=$addresseeName]]"/>
    22.       </xsl:when>
    23.       <xsl:otherwise>
    24.          <xsl:apply-templates/>
    25.       </xsl:otherwise>
    26.    </xsl:choose>
    27. </xsl:template>

    But that's mind-numbing stuff and I certainly wouldn't be able to help you.

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    You can use .Net xml classes to find the differences, but differences really depend on the structure of the XML documents in queston.

    I mean I could have
    Code:
    <root>
    <Address>
    <AddressID>1</AddressID>
    <StreetNumber>111</StreetNumber>
    </Address>
    <Address>
    ...
    and
    Code:
    <root>
    <Address>
    <AddressID>1</AddressID>
    <StreetNumber>123</StreetNumber>
    </Address>
    <Address>
    ...
    And you could certainly tell that for the Address uniquely identified by 1, there is a difference in the two XML documents (the streetnumber is differen).

    Or, it could be that the 2nd XML document has a different address structure :
    Code:
    <root>
    <Address>
    <AddressID>1</AddressID>
    <StreetNumber>111</StreetNumber>
    <StreetName>Franklin</StreetName>
    </Address>
    <Address>
    ...
    in which case the difference would be this 2nd file has a StreetName child attribute.

    So, which is the one you want?

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2004
    Posts
    48
    i guess the first example of the xml document is what i am looking for. what i'm doing is scanning a computer for software. and then after a few days later scan the machine again. and then compare the two scans. i'm writing the files as xml schemas....thanks
    Last edited by dawgfather; Apr 30th, 2004 at 10:21 AM.

  5. #5
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651
    I suppose you want .NET code to compare XML files but in the meantime have a look at this tool XML Diff Demo
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width