This is a reference guide I have compiled over time for those of you looking to do a little more with XML in InDesign (originally published Feb. 2011, last updated Feb. 2018). If you have any extra information you’d like to see added to this guide, feel free to message me.

Mapping XML tags to InDesign styles

Mapping XML tags to styles creates a link between content marked up with an XML tag and a paragraph, character style, table or cell style and will subsequently format the run-in XML data in the InDesign document based on the mapping references.

To map XML tags to various InDesign styles:

  1. Select Map Tags to Styles from the Tags panel menu or the Structure pane menu.

The Tags panel lists all available tags. The Style menu provides a drop-down menu next to each Tag that contains a list of all Paragraph, Character, Table and Cell Styles to which Tags may be mapped.

  1. Click Map by Name in the Map Tags to Styles dialog box to automatically map matching Tag and Style names. All matching names are automatically linked up. For any Tags not mapped, you can choose an alternative mapping option from the drop-down menu.
  2. After you’ve linked all used tags to document styles, click OK.

Imported XML data is formatted now automatically formatted using the matched paragraph, character, table and cell styles.

InDesign Namespace

When defining attributes that refer to a specific eXtensible Markup Language Namespace (XMLNS), the namespace must be declared as part of the XML. Where InDesign 4.0 and 5.0 namespaces are used, both namespaces may be entered in the Root element of the XML file or else inside the element referring to them.

Namespace
<Root xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" 
xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">

Figure 1. InDesign Namespace reference for version 4 and 5.

Images

An image reference in XML must provide a full path-name to the image location as a href attribute (this is similar to how the img tag works in HTML). When you apply an Object Style to the graphic frame that sets the frame options, you can control the image’s positioning and scaling as it is placed in a tagged graphic frame during XML import.

Image element sample
<Image href="File:///Volumes/DOCS_IMAGES/2008_Sydney/IMG_1806.JPG"></Image>

Figure 2. Example of Image element with reference to image location

Image reference examples
Images stored in the same folder as the XML filehref="File:///image.jpg"
Images stored in a subfolder inside the same folder as the XML filehref="File:///foldername/image.jpg"
Images stored anywhere and referenced by accessing the full path name. This is referred to as an absolute path nameIn the Documents folder on your PC: href="File:///C:/Users/username/Documents/
RestOfPath/image.jpg"
 In the Documents folder on your Mac: href="File:///Users/username/Douments/
RestOfPath/image.jpg"
 Where username is to be replaced with your username (in my case that would be “carijansen”) and RestOfPath points to sub and sub-sub-folders inside the Documents folder
Images stored on another volume (server)from a Macintosh OS: File:///Volumes/VolumeName/RestOfPath
 Where VolumeName reflects the volume.
from Windows: File:///Servername/RestOfPath
Where ServerName reflects the name of the Server you’re connected to.

Figure 3. Image path samples.

Tables

Tables in InDesign CS3 and higher can be formatted using Table and Cell Styles.

These styles may be applied as part of the XML import by including appropriate style attributes to the XML table. The following attributes can be applied:

aid:tabledefines that the element is a table
aid:trows total number of rows the table contains
aid:tcols total number of columns the table contains
aid5:tablestyle(ID5 specific), Table Style that formats the table
aid:theaderdefines cells as being part of a header row
aid:tfooterdefines cells as being part of a footer row
aid5:cellstyle (ID5 specific), Cell Style that formats table cells
aid:crowsnumber of rows across which the cell spans
aid:ccolsnumber of columns across which the cell spans
aid:ccolwidthcolumn width of cell, measured in points

Figure 4. Table attributes.

XML Example
<Table aid:table="table" aid:trows="2" aid:tcols="4" aid5:table style="TableWithHeader">
<Cell aid:table="cell" aid:theader="" aid:crows="1" aid:ccols="4" aid:ccolwidth="134">Table heading here</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="134">Fruit flies</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="134">23</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="134">34</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="134">234.9</Cell>
</Table>

Figure 5. Table XML sample.

Note that a table cannot be placed into InDesign without its parent Story element. The aid and aid5 prefixes used in the attribute names that define specific cell formatting indicate that these names are part of the InDesign 4.0 and 5.0 XML namespaces.

Paragraph and character styles

Formatting with paragraph or character styles can also occur during XML import and works similarly to using the table attributes. Use the following attributes for paragraph or character level formatting:

AttributeDescription
aid:pstyleParagraph Style formatting
aid:cstyleCharacter Style formatting

Figure 6. Paragraph and character style attributes.

XML example
<title aid:pstyle="head_large">van Gogh Art Exhibition</title>
<intro>Vincent Willem van Gogh <dob aid:cstyle="smallcaps">
(30 March 1853 – 29 July 1890)</dob> was a Dutch ... most popular and most expensive pieces.</intro>
<body>Van Gogh spent his early dult life ... until he encountered Impressionism and Neo-Impressionism in Paris.</body>

Figure 7. Paragraph and character style XML sample.

Special characters

List of special characters (I’ll add to this over time; feel free to message me if you have additions):

CharacterDescription
en-dash&#8211;
em-dash&#8212;
en-space&#x2002;
em-space&#x2003;
 tab&#x0009;
 1/4&#x00BC;
 1/2&#x00BD;
 3/4&#x00BE;

Figure 8. Special characters.