Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to compare 2 XML files ?

Status
Not open for further replies.

sergeiY

Programmer
Feb 13, 2003
132
AU
This is want I need to do:

compare 2 directory structures on 2 servers and report any changes

this is what I think I need to do:

generate 2 XML files and then compare them

the first bit is easy I can generate XML files but it seems that comparing XML files is very serious stuff...

Also I need to use ASP to do it. Can I somehow load XML file to ASP structure or variable and then use ASP to compare them ???

Any help will be greatly appreciated
 
Depending on what kind of output you want, there are many diff'ing tools on the market... as to which ones plug into ASP I have no idea, but if you basically want a line by line difference, don't narrow yourself to comparing XML files when you look around for technology...

Araxis merge is quite popular here... the simple diff'ing provided by emacs is also quite useful... I'm sure there're more.

-Rob
 
Rob

I am building application that needs to compare 2 XML files programaticaly... I can't use any tools or COMs. I am looking for XSL or ASP technical solution that will let me do this...
 
>> ASP technical solution

don't know what that means

>> I am looking for XSL

XSL will not compare two files -There are only 10 types of people in the world, those who understand binary and those who don't-

-pete
 
Pete

this is what I got from a fellow programmer in other team and it does work !

<?xml version=&quot;1.0&quot;?>
<?xml:stylesheet type=&quot;text/xsl&quot; href=&quot;compare.xsl&quot;?>
<files>
<file href=&quot;file1.xml&quot; />
<file href=&quot;file2.xml&quot; />
</files>

<xsl:stylesheet version=&quot;1.0&quot;
xmlns:xsl=&quot;<xsl:eek:utput method=&quot;xml&quot; indent=&quot;yes&quot;/>
<xsl:variable name=&quot;file1&quot;
select=&quot;document(/files/file[1]/@href, /)&quot; />
<xsl:variable name=&quot;file2&quot;
select=&quot;document(/files/file[2]/@href, /)&quot; />
<xsl:template match=&quot;/&quot;>
<compare_result>
<changed_items>
<xsl:apply-templates select=&quot;$file1//BORROWER&quot; mode=&quot;changed&quot;/>
</changed_items>
<deleted_items>
<xsl:apply-templates select=&quot;$file1//BORROWER&quot; mode=&quot;deleted&quot;/>
</deleted_items>
<added_items>
<xsl:apply-templates select=&quot;$file2//BORROWER&quot; mode=&quot;added&quot;/>
</added_items>
<unchanged_items>
<xsl:apply-templates select=&quot;$file1//BORROWER&quot; mode=&quot;unchanged&quot;/>
</unchanged_items>
</compare_result>
</xsl:template>

<xsl:template match=&quot;//BORROWER&quot; mode=&quot;deleted&quot;>
<xsl:variable name=&quot;borrowerID&quot; select=&quot;@XNT_IVP_ID&quot;/>
<xsl:if test=&quot;not($file2//BORROWER[@XNT_IVP_ID=$borrowerID])&quot;>
Deleted: <xsl:copy-of select=&quot;.&quot;/>
</xsl:if>
</xsl:template>

<xsl:template match=&quot;//BORROWER&quot; mode=&quot;changed&quot;>
<xsl:variable name=&quot;borrowerID&quot; select=&quot;@XNT_IVP_ID&quot;/>
<xsl:if test=&quot;$file2//BORROWER[@XNT_IVP_ID=$borrowerID]&quot;>
<xsl:if test=&quot;not(.=$file2//BORROWER[@XNT_IVP_ID=$borrowerID])&quot;>
Changed: <xsl:copy-of select=&quot;.&quot;/>
</xsl:if>
</xsl:if>
</xsl:template>

<xsl:template match=&quot;//BORROWER&quot; mode=&quot;added&quot;>
<xsl:variable name=&quot;borrowerID&quot; select=&quot;@XNT_IVP_ID&quot;/>
<xsl:if test=&quot;not($file1//BORROWER[@XNT_IVP_ID=$borrowerID])&quot;>
Added: <xsl:copy-of select=&quot;.&quot;/>
</xsl:if>
</xsl:template>

<xsl:template match=&quot;//BORROWER&quot; mode=&quot;unchanged&quot;>
<xsl:variable name=&quot;borrowerID&quot; select=&quot;@XNT_IVP_ID&quot;/>
<xsl:if test=&quot;$file2//BORROWER[@XNT_IVP_ID=$borrowerID]&quot;>
<xsl:if test=&quot;.=$file2//BORROWER[@XNT_IVP_ID=$borrowerID]&quot;>
Unchanged: <xsl:copy-of select=&quot;.&quot;/>
</xsl:if>
</xsl:if>
</xsl:template>

</xsl:stylesheet>
 
I just have too much new information I need a bit more time to absorb it... It seems like this XSL solution is what I am looking for :)

When I said technical solution I meant I want to do code myslef and have it as part of my application. I am building a reporting tool for non technical users so they just need to click one button and get nice and clear report.
 
>> XSL will not compare two files

oops, what i meant was that you can't ask it if the files are equal. XSL can only produce a textual output not a programatic true/false type response. -There are only 10 types of people in the world, those who understand binary and those who don't-

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top