Announcement

Collapse
No announcement yet.

Tutorial: Comparing XML configuration files

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Michael Bulgrien
    replied
    I believe that Team Scooter has plans for an XML compare in a future version of the product.
    But, yes, I agree that it would be really cool to have a text-based XML compare in which one could apply an XSLT to both sides of the compare...with an option/session setting to replace ending tags with ending slashes on single-line XML nodes.

    Leave a comment:


  • RodolfoGiovanninetti
    replied
    Thank You very much for the help! Now, it is up to ScooterSoftWare to develop a plug in, based on Your idea, so that all steps are done automatically by B.C.3 when I compare two .xml files.

    Thank You very much again

    Rodolfo Giovanninetti

    Leave a comment:


  • Michael Bulgrien
    started a topic Tutorial: Comparing XML configuration files

    Tutorial: Comparing XML configuration files

    Comparing XML files can be problematic when the nodes are in a different order in each file. This tutorial demonstrates how to use an XSLT (Extensible Stylesheet Language Transformations) file to sort XML documents before comparing them in BeyondCompare.

    Step 1
    You'll need an XML editor. For this tutorial I'm using the free XRay XML Editor from archiTAG international. If you don't have an XML editor, download and install XRay from here:

    XRay2 XML Editor

    Step 2
    Create a text file, paste in the code snippet below, and save it as an XSLT file. Since this file is a generic XSLT file to sort any XML file, I've saved mine as:

    GenericSort.xslt

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes" />
    
    <xsl:template match="@* | /">
    <xsl:copy>
    <xsl:apply-templates select="@* | node()" />
    </xsl:copy>
    </xsl:template>
    
    <xsl:template match="*">
    <xsl:copy>
    <xsl:apply-templates select="@*" />
    <xsl:apply-templates select="*">
    <xsl:sort order="ascending" data-type="text" select="local-name()" />
    </xsl:apply-templates>
    </xsl:copy>
    </xsl:template>
    </xsl:stylesheet>

    Step 3
    Open the XSLT file in XRay. Also bring in the XML files you wish to compare.

    See Screencast

    Step 4
    Apply the XSLT to both XML files and save the results as new sorted XML files.

    See Screencast

    Step 5
    Open the sorted XML files in BeyondCompare. You may have noticed that the XSLT transform changed the XML format by adding XML closing tags to each element. No worries. A simple regular expression find and replace will return the XML to its original format.

    Click Search -> Replace... Remove the checkmark from the "Match character case" option and perform a regular expression find and replace using the following values (without the quotes):

    Text to find: "></[a-z]+>"
    Replace with: " />"

    Don't forget the leading space on the replace with value, choose Both sides, then click Replace All.

    See Screencast


    That's all there is to it.
    Merge any values that you need to.
    When you close Beyond Compare, you will be asked if you want to save the changes.
Working...
X