|
Home > Online Product Documentation > Table of Contents > Diffing Folders and XML Documents Diffing Folders and XML Documents
During application development, it can be useful to be able to compare two or more XML documents, or to compare the contents of two folders, in order to identify the type and number of differences between them. The process of comparing one document (or folder) with another is referred to as diffing. Stylus Studio provides utilities for diffing folders and documents. For more informationStylus Studio provides a video demonstration of Stylus Studio's XML Diff tool. Visit our Web site to view this and other Stylus Studio video demonstrations: http://www.StylusStudio.com/xml_videos.html In this sectionThis section covers the following topics: OverviewStylus Studio's Diff tool lets you easily compare two or more versions of the same document in the XML Diff Viewer (as shown in Figure 130), or the contents of two folders (as shown in Figure 134).
Customizable color-coding lets you quickly determine how one document differs from another - green, for example, identifies objects (such as elements and attributes) that are present in the target document, but which do not exist in the source document. When you hover the pointer over symbols displayed in the side bars of the source and target document windows, Stylus Studio displays a tool tip that indicates the specific nature of the change. In this sectionThis section covers the following topics: Sources and TargetsWhen you use Stylus Studio to diff documents (or folders), you select a source and a target. Stylus Studio considers the source document or folder to be the baseline, or current standard; the target document or folder is assumed to be some other version (it might be older or newer, for example) of the source. The Stylus Studio Diff tool illustrates how this other version, the target, differs from the source (or sources) you have selected.
The Diff Configuration File
You can save the information associated with a given XML diff session in a
diff configuration file. Diff configuration files make it easy to perform a diff on the same set of XML documents over time. Examples of the information saved with the diff configuration file include the URLs of the source and target documents, and any settings made on the
XML Diff menu or toolbar. Diff configuration files are created with a
Changes made to the source and target documents are detected by Stylus Studio the next time you open the diff configuration file, allowing you to diff the files at that time. (Whether or not the diff is run automatically when you open the diff configuration file depends on Autorun Diff settings on the Engine page of the Options dialog box. See When Does the Diff Run? for more information.) What Diffs Are Calculated?This section describes how Stylus Studio diffs XML documents and folders. DocumentsThe Stylus Studio Diff engine compares source and target documents in their entirety. If you want, you can use the Engine page of the Options dialog box to exclude certain items from the diff calculation. These items include: You can also specify whether or not you want Stylus Studio to: See Modifying Default Diff Settingsto learn how to set these and other diff options. FoldersOptions for diffing XML documents do not affect how Stylus Studio diffs folders. When diffing folders, Stylus Studio compares one folder's contents with another. See Diffing Foldersfor more information on this topic. Tuning the Diffing AlgorithmThe purpose of any diffing tool is to identify the list of logical operations required to change the source document into the target document. Examples of logical operations include additions, revisions, and deletions. Even diffs between simple XML documents can yield a long list, sometimes with redundant operations. Ideally, the list of operations should be reduced to make it as economical as possible; that is, the list should be able to answer the question, What are the fewest number of changes required to turn the source into the target? Calculating such a list can be time-consuming and resource intensive, and these costs might not be worth the benefits to a given user. For this reason, Stylus Studio provides settings that let you tune the diffing algorithm used by the XML Diff engine. Tuning settings are displayed in the Performance group box on the Engine page of the Options dialog box.
You can
Handling Large DocumentsThe Optimize for large documents with few changes setting helps speed the diffing of large (greater than 1MB) documents. This setting can be used in conjunction with any of the algorithm tuning settings and is on by default. When Does the Diff Run?Stylus Studio runs the diff automatically, as soon as you specify the target document or folder. Whether or not subsequent changes cause Stylus Studio to automatically recalculate the diff is determined by the Autorun Diff settings on the Engine page of the Options dialog box. Changes that can make a diff recalculation necessary include adding new source and target documents, changing the underlying source and target documents themselves, or to changes to certain Engine settings. Options That Affect When the Diff RunsThese settings, on the Engine page of the Options dialog box, determine when and whether Stylus Studio automatically recalculates the diff.
See Modifying Default Diff Settingsto learn more about setting these and other Diff options. Running the Diff Manually
You can run the diff manually by clicking the Calculate diff button (
You can also run the diff from the command line. See Running the Diff Tool from the Command Line. Symbols and Background ColorsStylus Studio uses symbols and background colors to alert you to differences in diffed documents and folders. The following table summarizes the symbols and default background colors, and the types of changes they represent.
You can change the background colors on the Presentation page of the Options dialog box. Combined Symbols
As described in
Table 13, Default Colors Used for Diffing Files and Folders, Stylus Studio displays a turquoise block (
Here, the
Additional Symbols for Diffing Multiple SourcesStylus Studio uses other symbols in the target document window when you diff multiple source documents. See Symbols Used in the Target Document Window. Diffing FoldersStylus Studio allows you to diff two folders. As shown in Figure 134, the Diff Folders dialog box displays the contents of each folder; symbols and colors, described in Symbols and Background Colors, identify the types of changes in the respective folders.
In this sectionThis section covers the following topics: FeaturesThe Diff Folders dialog box has several features that make it easy to diff folders and the XML documents they contain:
How to Diff FoldersTo diff folders:
1. Select
Tools > Show Differences In > Folders from the Stylus Studio menu.
The Diff Folders dialog box appears.
2. Click the
Choose Source Folder button (
The Select Source Folder dialog box appears.
3. Expand the
Desktop tree and navigate to the folder you want to use as the source folder for the diff.
4. Click
Open.
The folder is displayed in the Source folder window of the Diff Folders dialog box. Stylus Studio performs the diff as soon as you select the target folder for comparison.
6. Optionally, use the
Show files of type drop-down list to filter the display to show only those files of the type you specify. (By default, Stylus Studio shows XML files - files with a
.xml extension.)
How to Diff Documents from the Diff Folders Dialog BoxYou can diff XML documents in the source and target folders directly from the Diff Folders dialog box. To diff two files from the Diff Folders dialog box:
1. Click the file you want to diff.
The document is shown as selected in both the
Source folder and
Target folder windows. In this illustration, the document
If you select a document that cannot be diffed, you will not see the selection in the opposite window.
2. Click the
Diff Files button.
Stylus Studio displays the XML Diff Viewer window. For more informationFor more information on diffing documents, see Diffing a Pair of XML Documents. The XML Diff ViewerThis section describes the XML Diff Viewer and its features, including the XML Diff Viewer toolbar and tools for loading documents. In this sectionThis section covers the following topics: OverviewSplit viewYou use the XML Diff Viewer to compare two or more XML documents. By default, the XML Diff Viewer displays the diffed documents on the Split View tab, which shows the documents side-by-side. The split view is shown in Figure 136.
In the split view, source documents are displayed on the left, the target document on the right. A splitter allows you to change the width of the source and target document panels. You can adjust the width of the source and target document panels by dragging the bar to the left and right. Merged viewIf you prefer, you can select the Merged View tab, which folds the nodes from the source and target documents into a single window, as shown in Figure 137 . Both views use the same symbols and color schemes to identify the types of changes detected by the Stylus Studio diff calculation - by default, green for added items, yellow for changed items, and red for removed items. The merged view displays changed items in pairs - the item from the target document appears first, the item from the source document is shown second, as shown in Figure 138.
In this example, the line through the
See Symbols and Background Colors for more information on this topic, and to learn how you can assign custom colors to the results of standard differencing operations. The XML Diff Viewer ToolbarThe XML Diff Viewer toolbar, shown in Figure 139, provides tools to help you The following table identifies the individual tools and tells you where to find more information.
Tools for Working with DocumentsThe XML Diff Viewer provides several tools for working with source and target documents:
When you click the add or set document button, Stylus Studio displays the
Open dialog box. The add button for source documents displays a green plus sign on it (
You use the remove button, the folder with the red minus sign on it (
Removing a Target Document
You cannot remove a target document. You can specify a
different target document by clicking the set target button (
Diffing a Pair of XML DocumentsThis section describes how to use Stylus Studio to diff a pair of XML documents. Before you beginBefore reading this section, you should read Overview, which describes basic information about the Stylus Studio Diff tool, and The XML Diff Viewer, which describes features of the XML Diff Viewer and how to use them. How to Diff a Pair of DocumentsTo diff a pair of documents:
1. Select
Tools > Options > Show Differences > Files from the Stylus Studio menu.
Stylus Studio displays the XML Diff Viewer.
2. In the source document window, click the add button (
Stylus Studio displays the Open dialog box.
3. Navigate to the document you want to load in the XML Diff Viewer.
4. Click
Open.
5. Repeat
step 2 through
step 4 for the target document, using the set button for the target document window (
By default, Stylus Studio runs the diff calculation automatically when you select the target document. If the default
On changes setting has changed, you need to run the diff calculation manually by clicking the
Calculate diff button (
Diffing Multiple DocumentsThis section describes how to use Stylus Studio to diff multiple XML documents. Before you beginBefore reading this section, you should read Overview, which describes basic information about the Stylus Studio Diff tool, and The XML Diff Viewer, which describes features of the XML Diff Viewer and how to use them. In this sectionThis section covers the following topics: Document FocusDiffing multiple XML documents is much the same as diffing a pair of documents - you specify the source documents (one at a time), a target document, and Stylus Studio calculates the diff.
When you diff multiple documents, however, only one source document can have focus at a time. Consider the following illustration, which shows three source documents (
In this example, the
When a source document has focus: Symbols Used in the Target Document WindowWhen diffing multiple documents, Stylus Studio uses an additional set of symbols in the target document window. These symbols, which are displayed in the side bar of the XML Diff Viewer window alongside the standard set of symbols described in Symbols and Background Colors, indicate the ways in which the change identified in the current source document differs from changes to the same node in other source documents.
As shown in
Figure 142, symbols in the column closest to the document tree identify the changes relative to the currently selected source. Here, the edit symbol (
The first column of symbols characterize changes in the currently selected source relative to other source documents. Here, for example, the red exclamation point (
Clicking on a document in this menu changes the current focus to that source document, allowing you to easily navigate to the same node in a different document. The additional symbols used by Stylus Studio when diffing multiple documents are described in Table 15.
ExampleConsider the example in Figure 144, which illustrates diffing three documents. In this example, the node in question is circled in red.
Notice that: Table 16 shows the symbols that might appear based on changing values to the node in question. The example illustrated in Figure 144 is shown in the first row. As values in the source documents change, Stylus Studio changes the diff symbol accordingly.
How to Diff Multiple DocumentsTo diff multiple documents:
1. Select
Tools > Options > Show Differences > Files from the Stylus Studio menu.
Stylus Studio displays the XML Diff Viewer.
2. In the source document window, click the add button (
Stylus Studio displays the Open dialog box.
3. Navigate to the document you want to load in the XML Diff Viewer.
4. Click
Open.
6. Repeat
step 2 through
step 4 for the target document, using the set button for the target document window (
By default, Stylus Studio runs the diff calculation automatically when you select the target document. If the default
On changes setting has changed, you need to run the diff calculation manually by clicking the
Calculate diff button (
Modifying Default Diff SettingsDefault settings for the behavior of the Diff engine and the appearance of diffed documents and folders are on the Engine and Presentation pages, respectively, of the Options dialog box. The Engine page, shown here, has settings that determine the conditions under which Stylus Studio runs the diff automatically, which items in a document (comments and text, for example) you want the diff engine to ignore, and settings that allow you to choose diffing algorithm tunings optimized for change description or time, for example.
Settings on the Engine page are reflected in the Diff editor tool bar, and in the XML Diff menu, shown here.
In this sectionThis section covers the following topics: |