InDesign

Import and merge XML

After you have created and tagged placeholder frames, tables, and text—and made sure that your document and the incoming XML file have the same tags and structure—you can import XML content into your layout.

You must use the Merge Content option to import XML into placeholders (or to replace existing content in your document). When merging content, InDesign replaces identically tagged and structured elements in your document with the imported XML elements. You can use additional import options to exclude imported (that is, filter) content that doesn’t match the document structure, to delete document items that aren’t matched or replaced by the imported XML, and to clone repeating XML elements.

If the imported XML file contains elements that are not found in the document, InDesign places these elements in the Structure pane without laying them out in your document.

To successfully merge XML into placeholders, keep these rules in mind:

  • Tag placeholders with the identical tag name as the XML element that will replace it (or be flowed into it).

  • In placeholder text, make sure any spacing, returns, tabs or static text is outside the placeholder element tags, but within the parent element for the story.

  • When you import the XML, select Do Not Import Contents Of Whitespace-Only Elements. (This preserves spacing and static text if the XML elements you import consist of white spaces only.)

Merge XML into existing content or placeholders

  1. Open the InDesign document that contains placeholders for the XML content.
  2. Open the Structure pane (View > Structure > Show Structure).
  3. Choose File > Import XML (or choose Import XML on the Structure pane menu) and then select the XML file you want to import.
  4. Select Show XML Import Options.
  5. Select Merge Content, and then click OK.
  6. To link the XML content to the original XML file, select Create Link.

    InDesign will list the XML file in the Links panel and display a yellow alert triangle in the panel if the XML source file changes.

  7. Select additional import options as needed:
    Clone Repeating Text Elements
    If you are importing repeating XML, clones a single placeholder element to create a container for each record in the file.

    Only Import Elements That Match Existing Structure
    Filters the incoming XML, so that elements that do not exist in the Structure pane are not imported.

    Do Not Import Contents Of Whitespace-Only Elements
    Preserves any spacing or static text inserted between elements in a placeholder frame.

    Delete Elements, Frames, And Content That Do Not Match Imported XML
    After XML has been imported, deletes any elements or placeholders in your document that were not matched (or replaced) by incoming data.

  8. Click OK.

InDesign merges content into the document starting with the first matching element in the XML file.

XML Import options

When importing and placing XML data using the Merge Content option, the XML Import Options dialog box offers the following options:

Create Link
Links to the XML file so that if the XML file is updated, you can update its XML data in your InDesign document.

Apply XSLT
Applies a stylesheet to define the transformation of the imported XML. Select Browse (Windows) or Choose (Mac OS) to select an XSLT file (.xsl or .xslt) from the file system. Use Stylesheet From XML, the default option, causes InDesign to use an XSLT processing instruction, if one is present in the XML file, to transform the XML data.

Clone Repeating Text Elements
Replicates the formatting applied to tagged placeholder text for repeating content. Create one formatting instance (for example, an address), and then reuse its layout to create other instances automatically. (See Working with repeating data.)

Only Import Elements That Match Existing Structure
Filters the imported XML content so that only elements from the imported XML file with matching elements in the document are imported.

Import Text Elements Into Tables If Tags Match
Imports elements into a table if the tags match the tags applied to the placeholder table and its cells. For example, use this option to place database records into a table when generating price lists or inventory sheets.

Do Not Import Contents Of Whitespace-only Elements
Leaves any existing content in place if the matching XML content contains only whitespace (such as a return or tab character). Use this option if you’ve included text between elements in your placeholder frames and you want to preserve this text. For example, when laying out recipes generated from a database, you might add labels such as “Ingredients” or “Instructions.” As long as the parent element that wraps each recipe contains only whitespace, InDesign leaves the label in place.

Delete Elements, Frames, and Content That Do Not Match Imported XML
Removes elements from the Structure pane and the layout of the document if they don’t match any elements in the imported XML file. Use this option to filter data from the document. For example, when importing names and addresses, you might have placeholder text for an element containing the company name. If one of the names doesn’t include the company element, InDesign deletes the element containing the placeholder text.

Import CALS Tables As InDesign Tables
Imports any CALS tables in the XML file as InDesign tables.