XML

XML (Extensible Markup Language) is a W3C initiative that allows information to be encoded in a structure that computers and humans can understand

The XML Data Provider is an optional module for EasyCatalog which enables EasyCatalog to link to an XML-formatted file. As with all EasyCatalog Data Providers, this link is bi-directional allowing changes made to the data within InDesign to be updated to the source XML file.

The XML Data Provider enables EasyCatalog to directly connect to your XML files. Creating and working with an XML data sources works in the same way as working from delimited files, although slightly more configuration is required.

The Data Provider makes heavy use of XPath to interrogate the XML file. XPath expressions are used to identify the location of each record and field within the XML.

The XML Data Provider also provides support for a wide range of character encodings including unicode (UTF-8 and UTF-16).

What is XPath

XPath is a language for finding information in an XML document, and is used by the XML Data Provider to navigate through elements and attributes in your XML document

XPath uses path expressions to select nodes or node-sets in an XML document. These path expressions look very much like the expressions you see when you work with a traditional computer file system.

In addition to being able to find and identify nodes, XPath also includes a number of functions, such as node value comparison, etc. The remainder of this manual assumes a working knowledge of XPath. For further information, please refer to the full language reference, which can be found on the following Web page: http://www.w3.org/TR/xpath

Configuring an XML data source

Configuring a data source is a relatively simple task and principally involves specifying various values within the XML Data Source Configuration dialog box.

As with all EasyCatalog data sources, the data source name must be unique and is used to identify your new data source. The name entered here will appear on the File→New→easyCatalog Panel menu.

The location of the XML file is shown here, and this file will be read when you create the data source and on subsequent ‘Synchronize with Data Source’ operations.

Displays the path to the currently selected XML file.

The XML Data Provider requires an XPath to identify the location of each record node within the XML. A pop-up menu, which has been populated based on the content of the XML file, is provided containing a list of valid XPaths. To use one of the example shown in the list, select it from the Examples pop-up menu.

Evaluates the ‘Record XPath’ expression and displays the number of records found in the XML file. To determine whether you have the correct record XPath, use the Evaluate button: this will show you how many records will be imported into EasyCatalog.

Displays a list of example XPath expressions. These are built from the parsed XML file.

This area of the dialog shows the fields that have been configured. An XPath must be provided for each of the fields you want to import from the record node. Create a new field using the ‘New’ button at the bottom of the dialog:

The Name of the field source will be the name of the field within EasyCatalog.

Enter the XPath to the field’s content in the Path field. This path is relative to the record XPath configured earlier.

Use the Examples pop-up menu to display an example list of XPath expression paths.

Use the Key check-box to define the key field for the Data Source.

The choice of key field is critical to the operation of EasyCatalog. The key field is used to uniquely identify each record from the data source and must never change.

EasyCatalog has the ability to load fragments of source XML into a field. This is specified using the Load as XML Fragment check box as shown on the Field Configuration dialog box. When this is checked the entire XML structure at the specified location is loaded into a field. This can be used by the complex table population feature or interrogated using custom field commands.

Example XML configuration

Use the following simple XML as an example:

<?xml version="1.0" encoding="UTF-8"?>
<section name = "Digital Camera Accessories">
    <category name="Kodak">
        <product stockcode="320-387-1010">
            <fields>
                <description>DC260/265/290 Lens adaptor</description>
                <price>787.00</price>
            </fields>
        </product>
        <product stockcode="320-387-1020">
            <fields>
                <description>Sanp Server 1200 1</description>
                <price>28.50</price>
            </fields>
        </product>
    </category>
    <category name="Canon">
        <product stockcode="320-387-1030">
            <fields>
                <description>30 BJC-70/80 battery</description>
                <price>787.00</price>
            </fields>
        </product>
        <product stockcode="320-387-1040">
            <fields>
                <description>BJ30 AC Adpator</description>
                <price>28.50</price>
            </fields>
        </product>
    </category>
</section>

The data in the above example for each record is contained within a product node. The record XPath for this node would be:

/section/category/product

Using the Evaluate button will report four instances of these nodes within the XML. This indicates that when the data source is fully configured, EasyCatalog will find four records from this XML structure.

Now that the record XPath has been configured, XPaths for each of the fields we want to import into EasyCatalog must be defined. In the example shown here, we want to import five fields - some of them are contained within the record node, others such as Category name and Section name must be retrieved from the record’s parent nodes.

XPaths for fields are relative to the record. So, for example, to retrieve the contents of the Price node, we would use the following XPath:

/fields/price/text()

To retrieve the contents of a parent node, such as the product’s category name , use .. to reference nodes and attributes higher up in the XML hierarchy:

../@name

This specifies the name attribute of the record’s parent node.

To retrieve the contents of the other nodes and attributes, the following XPaths would be used:

Updating the Data source

In the same way file based data sources are updated, EasyCatalog has the ability to update XML data sources. A snapshot of the XML file is stored when a data source is created or synchronized, so EasyCatalog will only update those nodes that have changed. This means any additional information in the XML which is not used by EasyCatalog will be preserved.

Reconfiguring the Data Source

The configuration for a XML Data Source can be modified later using the Information dialog box. Click the Info button at the bottom of the EasyCatalog panel, then use the Configure... button to change the settings for the data source.

Key fields

Once a data source has been configured, only the XPath attribute for key fields can be amended. Key fields cannot be renamed or deleted after the initial configuration. This prevents links on your document from being broken by modifying the key fields.

Last updated