Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Compare XML Files

You can use the Comparison tool to compare a pair of XML text files. The tool processes the results into a report that you can use to explore the file differences. You can compare XML files with a text comparison or a hierarchical XML comparison.

You can access the XML comparison tool from the Current Folder browser , the Comparison Tool, or programmatically using the visdiff function.

The XML comparison compares the files using the “Chawathe” algorithm, as described in this paper:

Change Detection in Hierarchically Structured Information, Sudarshan Chawathe, Anand Rajaraman, and Jennifer Widom; SIGMOD Conference, Montreal, Canada, June 1996, pp. 493-504.

This conference paper is based upon work published in 1995: see http://dbpubs.stanford.edu:8090/pub/1995-45.

XML comparison reports display in the Comparison Tool. For more information about the Comparison Tool, see Comparing Files and Folders.

The XML comparison report shows a hierarchical view of the portions of the two XML files that differ. The report does not show sections of the files that are identical.

If the files are identical you see a message reporting there are no differences.

Note

It might not be possible for the analysis to detect matches between previously corresponding sections of files that have diverged too much.

Change detection in the Chawathe analysis is based on a scoring algorithm. Items match if their Chawathe score is above a threshold. The implementation of Chawathe's algorithm uses a comparison pattern that defines the thresholds.

Choose XML Files to Compare

From the Current Folder Browser

To compare two files from the Current Folder browser:

  • For two files in the same folder, select the files, right-click and select Compare Selected Files/Folders.

  • To compare files in different folders:

    1. Select a file, right-click and select Compare Against

    2. Select the second file to compare in the Select Files or Folders for Comparison dialog box.

    3. Select the Comparison type XML text comparison.

    4. Click Compare.

The XML comparison tool performs a Chawathe analysis on the files and displays a report in the Comparison Tool. The file you right-click to launch the XML comparison tool displays on the right side of the report.

For more information about comparisons of other file types with the Comparison Tool, such as text, MAT or binary, see Comparing Files and Folders.

Compare From the Comparison Tool

To compare files using the Comparison Tool, from the MATLAB® Toolstrip, in the File section, select the Compare button. In the dialog box select files to compare.

If the files you select to compare are XML files and you select an XML comparison, the XML comparison tool performs a Chawathe analysis of the XML files, and generates an report.

Compare From the Command Line

To compare XML files from the command line, enter

visdiff(filename1, filename2, 'xml')

where filename1 and filename1 are XML files.

Change Comparison Type

If you specify two XML files to compare using either the Current Folder Browser or the visdiff function, then the Comparison Tool performs the default comparison type for the selected files. You can compare XML files with a text comparison or a hierarchical XML comparison.

To change comparison type, either create a new comparison from the Comparison Tool, or use the Compare Against option from the Current Folder browser. You can change comparison type in the Select Files or Folders for Comparison dialog box. Select XML text comparison before clicking Compare.

Navigate the XML Comparison Report

The XML comparison report shows changes only. The report is a hierarchical view of the differences between two XML text files, and is not a hierarchical view of the original XML data.

To step through differences, use the Comparison tab on the toolstrip. To move to the next or previous group of differences, on the Comparison tab, in the Navigate section, click the arrow buttons to go to the previous or next difference.

You can also click to select items in the hierarchical trees.

  • Selected items appear highlighted in a box.

  • If the selected item is part of a matched pair it is highlighted in a box in both left and right trees.

Report item highlighting indicates the nature of each difference as follows:

Type of report itemHighlightingNotes
ModifiedPinkModified items are matched pairs that differ between the two files. When you select a modified item it is highlighted in a box in both trees.
Changed parameters for the selected pair are displayed underneath. If the text is too long to display, select Compare to open a new comparison of the parameters.
UnmatchedGreenWhen you select an unmatched item it is highlighted in a box in one tree only.
ContainerNoneRows with no highlighting indicate a container item that contains other modified or unmatched items.

Use the Comparison tab for the following functions:

  • Refresh — Run Chawathe analysis again to refresh the comparison report.

  • Swap Sides — Swap sides and rerun comparison. Runs the Chawathe analysis again.

  • Save As > HTML — Opens the Save dialog box, where you can choose to save a printable version of the XML comparison report. The report is a noninteractive HTML document of the differences detected by the Chawathe algorithm for printing or archiving a record of the comparison.

  • Save As > Workspace Variable — Export XML comparison results to workspace.

  • In the Navigate section, click the arrow buttons (or press Up or Down keys) to go to the previous difference or go to the next difference.

  • Compare Selected Parameter — Open a new report for the currently selected pair of parameters. Use this when the report cannot display all the details in the Parameters pane, e.g., long character vectors or a script.

Use the View tab controls on the toolstrip for the following functions:

  • Expand All — Expands every item in the tree.

    Tip

    Right-click to expand or collapse the hierarchy within the selected tree node.

  • Collapse All — Collapses all items in the tree to the most compact view possible.

Note

It may not be possible for the analysis to detect matches between previously corresponding sections of files that have diverged too much.

Save Comparison Log Files in a Zip File

Temporary XML comparison files accumulate in tempdir/MatlabComparisons/XMLComparisons/TempDirs/. These temporary files are deleted when you close the related comparison report.

You can zip the temporary files (such as log files) created during XML comparisons, for sharing or archiving. While the comparison report is open, enter:

xmlcomp.zipTempFiles('c:\work\myexportfolder')

The destination folder must exist. The output reports the zip file name:

Created the zipfile "c:\work\myexportfolder\20080915T065514w.zip"

To view the log file for the last comparison in the MATLAB Editor, enter:

xmlcomp.showLogFile

Export Results to the Workspace

To export the XML comparison results to the MATLAB base workspace,

  1. On the Comparison tab, in the Comparison section, select Save As > Save to Workspace.

    The Input Variable Name dialog box appears.

  2. Specify a name for the export object in the dialog and click OK. This action exports the results of the XML comparison to an xmlcomp.Edits object in the workspace.

The xmlcomp.Edits object contains information about the XML comparison including file names, filters applied, and hierarchical nodes that differ between the two XML files.

To create an xmlcomp.Edits object at the command line without opening the Comparison Tool, enter:

Edits = xmlcomp.compare(a.xml,b.xml) 

Property of xmlcomp.EditsDescription
FiltersArray of filter structure arrays. Each structure has two fields, Name and Value.
LeftFileNameFile name of left file exported to XML.
LeftRootxmlcomp.Node object that references the root of the left tree.
RightFileNameFile name of right file exported to XML.
RightRootxmlcomp.Node object that references the root of the right tree.
TimeSavedTime when results exported to the workspace.
VersionMathWorks® release-specific version number of xmlcomp.Edits object.
Property of xmlcomp.NodeDescription
ChildrenArray of xmlcomp.Node references to child nodes, if any.
EditedBoolean — If Edited = true then the node is either inserted (green) or part of a modified matched pair (pink).
NameName of node.
ParametersArray of parameter structure arrays. Each structure has two fields, Name and Value.
Parentxmlcomp.Node reference to parent node, if any.
PartnerIf matched, Partner is an xmlcomp.Node reference to the matched partner node in the other tree. Otherwise empty [].

Related Topics

Was this topic helpful?