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.
Printable View
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.
You could probably get away with writing XSL that would be the envy of your peers:
VB Code:
<?xml version='1.0'?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml"/> <xsl:variable name="doc-file">[url]http://mymachine.com/changed.xml[/url]</xsl:variable> <!-- copy everything that has no other pattern defined --> <xsl:template match="* | @*"> <xsl:copy><xsl:copy-of select="@*"/><xsl:apply-templates/></xsl:copy> </xsl:template> <!-- check for every <address> element if an updated one exists --> <xsl:template match="//address"> <xsl:param name="addresseeName"> <xsl:value-of select="addressee"/> </xsl:param> <xsl:choose> <xsl:when test="document($doc-file)//addressee[text()=$addresseeName]"> <xsl:copy-of select="document($doc-file)//address[child::addressee[text()=$addresseeName]]"/> </xsl:when> <xsl:otherwise> <xsl:apply-templates/> </xsl:otherwise> </xsl:choose> </xsl:template>
But that's mind-numbing stuff and I certainly wouldn't be able to help you.
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
andCode:<root>
<Address>
<AddressID>1</AddressID>
<StreetNumber>111</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).Code:<root>
<Address>
<AddressID>1</AddressID>
<StreetNumber>123</StreetNumber>
</Address>
<Address>
...
Or, it could be that the 2nd XML document has a different address structure :
in which case the difference would be this 2nd file has a StreetName child attribute.Code:<root>
<Address>
<AddressID>1</AddressID>
<StreetNumber>111</StreetNumber>
<StreetName>Franklin</StreetName>
</Address>
<Address>
...
So, which is the one you want?
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
I suppose you want .NET code to compare XML files but in the meantime have a look at this tool XML Diff Demo