Home / Articles / Adobe InDesign / Real World Adobe InDesign CS4: XML

Real World Adobe InDesign CS4: XML

Article Description

XML is as simple or complicated as you care to make it. Olav Martin Kvern and David Blatner show you how to keep it simple, at least at first.
Importing and Exporting XML

Importing and Exporting XML

To import XML into the structure of an InDesign document, follow these steps. If you want to import the XML into a specific XML element, select the element first.

  1. Choose Import XML from the File menu (or from the Structure menu or Context menu in the Structure view). InDesign displays the Import XML dialog box.
  2. Locate and select an XML file to import.
  3. Turn on the Show Import Options option (most of the time, we think you’ll want to have this option turned on). To import the XML into the selected element, turn on the Import Into Selected Element option.
  4. Click the Open button. InDesign displays the XML Import Options dialog box (see Figure 14-21).
  5. Figure 14.21 XML Import Options Dialog Box

  6. Make any changes you need in the XML Import Options dialog box (see “XML Import Options,” later in this chapter).
  7. Click the OK button. InDesign adds the XML data to the document.

When you import XML for the first time, the incoming XML data will appear in any page items that have been tagged with the Root XML element.

XML Import Options

The options in the XML Import Options dialog box control the way that InDesign imports XML into the XML structure in your document. The following is a brief summary of the options.


If you’re importing XML into a document that already contains an XML structure, you can choose to replace the existing structure, or add the incoming XML to the existing structure. To specify the former, choose Merge Content from the Mode pop-up menu; for the latter, choose Append Content. These options mirror the options of the same name in the Import XML dialog box, but it’s nice to be able to change your mind once you get here.

Create Link.

When this option is turned on, InDesign will create a link to the imported XML data file. When the original file is modified, you’ll have the option of updating the link. This comes with the same advantages and disadvantages (mainly disadvantages, in our opinion) as creating links to text files, as discussed in Chapter 7, “Importing and Exporting.”

Apply XSLT.

You can apply an XSLT stylesheet to the incoming XML. For more on this topic, see “Applying XSLT Stylesheets on Import/Export,” and “Transforming XML with XSLT,” later in this chapter.

Clone Repeating Text Elements.

It’s almost impossible to understate the importance of this control. With it turned on, and with a properly-constructed layout template, you can automate the placement of thousands of fully-formatted XML elements, including inline graphics. When it’s turned off, you’ll be stuck placing and formatting element after element by hand. But that all has to do with the template. Take a look at “Creating Placeholders for Repeating Content,” later in this chapter.

Only Import Elements That Match Existing Structure.

When you’ve turned on this option, InDesign attempts to match XML elements in the incoming XML structure with the structure in the file. If an elements in the incoming data does not match an element in the existing structure, InDesign does not import that element.

Import Text Elements into Table if Tags Match.

When this option is on, and if the incoming XML data replaces an existing table, InDesign will import the contents of the XML elements into the table.

Do Not Import Contents of Whitespace-Only Elements.

Are the returns, tabs, and other “whitespace” characters in the incoming XML important? If so, turn this option off. If, on the other hand, you have created a template that provides returns, tabs, and static text, turn this option on.

Delete Elements, Frames, and Content That Do Not Match Imported XML.

When you turn this option on, InDesign will delete any frames, graphics, or text that do not have a match in the XML file you’re importing. It’s something like the logical opposite of the Only Import Elements That Match Existing Structure option, as applied to layout items.

Import CALS Tables as InDesign Tables.

CALS stands for “Continuous Acquisition and Life-cycle Support,” a U.S. Department of Defense (you know, where the Web came from) initiative/standard for documentation markup. The CALS specification for tables was adopted for use in SGML (Standard Generalized Markup Language). It’s a standard for marking up tables. We’ve never seen it, but we understand others might have. If you think that the incoming XML file contains some tables formatted using this standard, turn this option on.

Applying XSLT Stylesheets on Import/Export

You can have InDesign apply an XSLT stylesheet as you import or export an XML file. To do this on import, choose an option from the Apply XSLT pop-up menu in the XML Import Options dialog box. On export, use the corresponding control in the Export XML dialog box.

This is very important because, as we mentioned earlier, the order in which XML elements appear in an InDesign layout might not be the ideal arrangement of the same elements in your XML data file. An XSLT transformation can fix that for you.

XSLT can rearrange elements, add or duplicate elements, and add or remove static text to make the incoming XML structure match the needs of your layout. On export, you can transform the outgoing XML to match the structure to other needs. For more on using XSLT, see “Transforming XML with XSLT,” later in this chapter.

Replacing XML

To replace an XML structure with elements from another XML file, follow these steps (see Figure 14-22).

Figure 14.22 Replacing XML

  1. If you want to replace any element other than the Root element, select an element in the Structure view.
  2. Choose Import XML from the File menu. InDesign displays the Import XML dialog box.
  3. Turn on the Replace Content option. If you want to replace the selected element, turn on the Import Into Selected Element option.
  4. Click the Open button, and InDesign replaces the XML elements with the elements in the XML file.

Exporting XML

Once you’ve created an XML structure in an InDesign document, you can export structure to an XML file. This is a good thing, because you can then use the exported XML file as a template for future files.

To export XML, follow these steps (see Figure 14-23).

Figure 14.23 Exporting XML

  1. If you want to export a selected element (and all of the elements it contains), select the XML element you want to export in the Structure view.
  2. Choose Export from the File menu. InDesign displays the Export dialog box.
  3. Choose XML from the Format pop-up menu and enter a name for the XML file.
  4. Click the Save button. InDesign displays the Export XML dialog box.
  5. Select an encoding for your exported XML document from the Encoding pop-up menu. If you want, you can choose to view the XML after exporting (and the browser you want to use for that purpose). If you want to export the selected element (if any), turn on the Export from Selected Element option.
  6. Click the Export button to export the XML file.

Exporting Structure Tags to PDF

Acrobat 5 PDF documents (PDF version 1.4 and above) can include eBook structure data. In essence, these are a defined set of XML tags that have a specific meaning to Acrobat.

The easiest way to tag the elements in your document with these tags is to choose the Add Untagged Items option from the Structure view menu. When you do this, InDesign automatically applies a tag named “Article” to untagged text frames and applies the tag “Figure” to untagged imported graphics.

You can create tags with these names and apply them. You can also use the tag name “Artifact” to mark page items you want to omit when the PDF is viewed on small-screen devices.

After you’ve applied these tags, turn on the Include eBook Tags option as you export PDF. The PDF will then be set up to reflow when displayed by the Acrobat Reader software.

5. Creating Placeholders for Repeating Content | Next Section Previous Section