Technical Writer, Production Support, Software Training

Adobe InDesign and XML: A Reference Guide

The following is a reference guide I have compiled over time for those of you who are looking at doing 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.

All Tags available in the Tags panel are listed. 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 positioning and scaling of the image as it is being 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 same folder as xml file href="File:///image.jpg"
images stored in a sub folder inside the same folder as xml file href="File:///foldername/image.jpg"
Images stored anywhere and referenced by accessing the full path name. This is referred to as an absolute path name In 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:table defines 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:theader defines cells as being part of a header row
aid:tfooter defines cells as being part of a footer row
aid5:cellstyle (ID5 specific), Cell Style that formats table cells
aid:crows number of rows across which the cell spans<
aid:ccols number of columns across which the cell spans
aid:ccolwidth column 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 as part of the attribute names that define specific cell formatting are indicative of these names being 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 similar to using the table attributes. Use the following attributes for paragraph or character level formatting:

Attribute Description
aid:pstyle Paragraph Style formatting
aid:cstyle Character 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):

Character Description
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.

Similar posts
  • How to change the colour of bullet points in InDesig... A few weeks ago I recorded a short quick tip tutorial. InDesign’s Control panel, gives users a quick and easy way to format text as a bulleted list. Highlight the text, and click the Bulleted List button in the Paragraph Formatting Controls mode for the Control panel. This applies a universal bullet character as the [...]
  • Creating a pop-up window in a PDF with Adobe InDesig... In the following YouTube tutorial, we’ll create an interactive PDF from Adobe InDesign, in which we click on a button, which in turn opens up a simple pop-up window containing a close-box. When the close-box is clicked the pop-up window disappears [...]
  • InDesign: Facing pages with odd-numbered left pages Back in 2004 I wrote a tip for InDesign CS on how you could have the first page of your document be a left page AND have it start with page number 1. It’s hard to believe this is almost a decade ago… But a recent question on Facebook, made me think I should really [...]
  • Negative Lookbehind – GREP for Designers This is the fourth and final blog-posts in a series of posts on lookaheads and lookbehinds in GREP, written after speaking at the Perth InDesign User Group. My speaker notes are also available: What is GREP? (PDF download) (2.4Mb). In the previous three posts I briefly introduced GREP, and we took a look at Positive [...]
  • Positive Lookbehind – GREP for Designers This is the third in a series of blog-posts about GREP, written after speaking at the Perth InDesign User Group. My speaker notes are also available: What is GREP? (2.4Mb PDF download). In the previous two posts I briefly introduced GREP, and we took a look at Positive Lookahead and Negative Lookahead. In this post [...]

5 Comments

  1. liuhua liuhua
    November 21, 2018    

    Hello, does the aid instruction set of the XML file have all? I need footnotes, Pinyin, picture size and other AID processing instructions, so as to better XML typesetting.

  2. Neil Neil
    September 25, 2018    

    Hi Cari,
    I’m working on producing a suite of InDesign documents, which will be populated using XML data, taken from our website.
    Some of the fields have inline styles, which appears as part of the text, when imported in to InDesign. (see below for example)

    <![CDATA[ Students often elect to undertake field trips either individually or as a group as part of their broad range of study. Bristol Zoo and a local zoo farm are favorite locations for the study of animals for Action Analysis studies.You’ll be given the opportunity to work with the British Film Institute (BFI) Animation Boot Camp, which provides workshop instruction for young people from around the UK. ]]>

    Is there any way to get InDesign to recognise this styling and either implement it or remove it?

    Thanks,
    Neil

    • Neil Neil
      September 25, 2018    

      Have just realised that all the inline styles have been implemented, here in the comments section. In the document , etc appear as text.

      • Neil Neil
        September 25, 2018    

        Drat, it did it again, even without closing tags. :/
        Hopefully you get the idea.

  3. June 16, 2018    

    This is the perfect webpage for everyone who would like to
    find out about this topic. You know a whole
    lot its almost tough to argue with you (not that I really would want to…HaHa).
    You certainly put a brand new spin on a topic which has
    been written about for ages. Great stuff, just excellent!

Leave a Reply

Your email address will not be published. Required fields are marked *