Adobe InDesign and XML: A Reference Guide

The following notes might be helpful for those of you who are looking at doing a little more with XML in InDesign. They are by no means complete, and I’ll likely update this post in the near future, to make it more complete.

Mapping tags to 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 that will subsequently format the data marked up with a particular tag. To map XML tags to styles, select Map Tags to Stylesfrom the Tags panel menu or the Structure pane menu.

The Map Tags to Styles dialog appears. 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.

To automatically map matching Tag and Style names, click Map by Name. All matching names are automatically linked up. For any Tags not mapped, you can choose an alternative mapping option from the drop down-menu.

After you’ve linked all used tags to document styles, click OK. Upon acknowledgement of the settings, imported XML content is formatted using the matched paragraph, character, table and cell styles.

When a document already contains a XML structure that is linked to content frames as well as tags to styles mapping and XML is imported, the laborious task of formatting text becomes a thing of the past.

Figure9. XML tags mapped to similarly named  paragraph styles.

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 1. 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 2. 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 3. 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>

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.

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. In the example above that would be the Tableelement.

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

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

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 5. 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>




This Post Has 51 Comments

  1. It needs to be kept away from the eyes and the areas around them.

    You should point out that it’s going to feel cold and that they should also avoid creasing their body too much.
    Why is Exfoliation Necessary for Spray Tanning Mature
    Skin. There is no need to spend hours on a beach or a rooftop.
    Working from the feet up will help you avoid marking or creasing the
    tan. To extend the life of your tan, do not use any harsh scrubs,
    exfoliates or loofahs. Indeed, self tanning is an instant way of getting that perfect bronze
    look. You can end up with a dirty looking result as the tanner doesn’t absorb so well in that area.
    It’s best to test a little bit before mixing up a batch.
    Other benefit of producing utilization of tanning beds and booths or spray tans
    can be the actuality how the treatment of tanning may be finished within handful of mins as well as you don’t should try and waste materials several
    hours even although in the heat from the sun.

  2. Having read this I thought it was extemely informative.
    Iappreciate you taking the time and energy to put this information together.
    I once again find myself perszonally spending way too much
    time both readfing and leaving comments. But so what, it was still worthwhile!

  3. Cari Jansen says:

    @locavore afaik there are no public updates for this. Adobe has however released more documentation on IDML. See: http://www.adobe.com/devnet/indesign/documentation.html

  4. locavore says:

    Where can we find out if there are any changes to XML namespace in more recent versions of InDesign (CC)? There is no online reference that I can find that says specifically if it is the same. I’d like to verify that the aid: should be changed or not for tables in InDesign CC
    xmlns:aid=”http://ns.adobe.com/AdobeInDesign/4.0/”
    xmlns:aid5=”http://ns.adobe.com/AdobeInDesign/5.0/”

  5. Cari Jansen says:

    @Pere

    You can use a workaround:
    if you need to access styleNameA in a style group, transform the <p aid:pstyle=”styleNameA”> to <styleNameA>, this way all you need to do is add a new style-mapping from </styleNameA><styleNameA> to “styleNameA (StyleGroupName)” .</styleNameA></p>

    • studiovanpelt says:

      Hi Cari, i didn’t understand that:
      For example in
      EK
      I want to get the “EK” paragraph style in a style group called “text”

      And in:

      Table header 1
      I want to get the “h2″ in a style group called “headers”.
      How do you do that?

      Thanks

      • Cari Jansen says:

        @studiovanpelt What is it you are trying to achieve? if you have a pstyle assigned as part of your xml import, it doesn’t map to a style inside a style group. If you are referring to a style group as part of xml-import you’ll likely need to use an xslt to get the import working, or xml-import script of sorts. Cari

  6. Pere says:

    id:pstyle with style in style group?

  7. Manikandan says:

    agatebook xmlns:aid=”http://ns.adobe.com/AdobeInDesign/6.0/”

  8. Manikandan says:

    Hai

    When i imported xml file into indesign version 6 “” as per your guidance aid:pstyle=”para” file not mapped as per style please advice.

    • Cari Jansen says:

      did you add the ns info to the start of the XML file? Is the paragraph style ‘para’ added in the paragraph styles panel? if it is in a style group remove it from the style group and add it at top level.

  9. William says:

    Hi Cari, Where shall a person find beginning instruction to use XML with InDesign? Thank you.

  10. Shaji says:

    Thanks for the valuable information about “aid” concept.
    How do we handle “Style Group” paragraph style.
    Using “aid:pstyle” it won’t work for Style Grouped paragraph style.
    Is there is any attribute which can handle the style grouped style.

    Shaji

  11. Cari Jansen says:

    @Johnny you’re most welcome. Glad it was helpful :) Cari

  12. johnnycho says:

    No, it was actually my typo, not yours, that was the issue. By the way, this is one of the most helpful and informative blog posts EVER. Thank you SO MUCH!

  13. Cari Jansen says:

    Not a problem Johnny. I’ve just reviewed the XML Notes in my blog post and fixed the ‘smart-quotes’ which I think might be the typo you were referring to? When I have some spare time I’ll add some additional notes to this blog-posts. Have added it to my list as a post that needs updating :) Cari

  14. johnnycho says:

    Please disregard my last message. I figured it out. A typo in the namespace declaration that you illustrated in Figure 4.

  15. johnnycho says:

    Thank you for this very helpful tutorial. I’m importing a table into my InDesign 5.5 file using XML. The table data shows up fine, but it’s not formatted, even though I have a basic table style and I’ve linked it to the table tag name. What’s strange is that when I select the data, the table styles are all greyed out, meaning it won’t let me apply a table style to the data. Have you ever run into this or do you know why it might be doing this? Thanks so much.

  16. SME says:

    Anwer, I mean update.:). BTW, Does Image is always referred using href or it can come without href tag? We are trying read indt XML programitically and wanted to have some reference base which will be always there to indicate image in XML.

  17. Cari Jansen says:

    @SME I was afraid that would be the answer :( :(

  18. SME says:

    Thanks for answer. It doesn’t work. We tried but no success. :(

  19. Cari Jansen says:

    @SME Hmmm… interesting question. I’ve never tried that, and my gut feel says ‘no’, as I’m not sure how InDesign could pull in the graphic and retain a link to it. As far as I’m aware, InDesign doesn’t support placing web graphics. But if you do get that working let us know for sure :)

  20. SME says:

    Can I use internet location for image tag? If Yes, how it would look like in XML?

  21. Cari Jansen says:

    @locavore interesting… must test that… I generally ensure when data is extracted from a database into XML-for-InDesign format, the row count is set.

  22. locavore says:

    Seems to me I had success leaving the aid:trows value empty (the rows would be calculated from the cells) — and if I set it to an arbitrary number, the table would truncate when it got to the value that matched cells count divided by that number. This was for a table that ran for many pages with repeating heads, developed quite some time ago and probably needs to be retested to verify aid:trows=”” is OK to use.

  23. Cari Jansen says:

    @David

    To give you a real life example: I developed an XML repetitive run-in template that generated a list of public schools some time ago and and each had their school crest included as part of the XML import. The crest needed to be fully visible and centered in a placeholder graphic frame.

    However, I’ve also recently worked on an XML run-in template, that is not repetitive, and indeed used a JavaScript that automatically applies at the end of the XML import and sizes certain images to a specific width/height.

    I guess in a way it depends on the kind of document template you are working on as to which works best.

    Cari

  24. dma says:

    Cari,

    You mentioned, “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.”

    Can you provide an example of an image element that would allow for position and scaling within inDesign on import? I currently assign an attribute to handle inline and breaking images but use that to apply a style via JavaScript. I have been unable to style, scale, or position an image them on import alone.

    Thanks.

    David

  25. Cari Jansen says:

    Hi Paul,

    You can use something like Oxygen XML Editor. Another one would be Stylus Studio (Windows only). As far as I’m aware both allow to build XSLT, apply to XML and see/test result.

    CJ

  26. Paul Harvey says:

    Hi Cari,

    Thanks for the suggestions. I’ll look into the XSLT row count – sounds like something to get my teeth into! In the meantime, I’ve changed the XSLT to create a table with two rows for each record and it works a treat.

    I’ve been attempting to remove empty elements using XSLT, but can’t seem to get it to work. I can’t work out whether it’s down to part of the XSLT (I’ve tried several examples from the net) or the way Indesign interprets it. Do you know of any software that will allow me to work on the Indesign XSLT ‘live’ (similar to the way Dreamweaver will allow you to work on live code)?

  27. Cari Jansen says:

    @Paul,

    Where I’ve worked with table data, we’ve calculated the amount of ‘rows’ (records) exported, so that the row number can be defined properly. You could possibly do this with XSLT as well (you’d need to check with an XSLT expert). The same applies for the empty elements, you can remove these during import (XSLT) or prior to import using something like a ‘GREP’ Find/Replace even.

    Cari

  28. Paul Harvey says:

    Hi Cari,

    Thank you for this information, I’ve learned a lot about Indesign, XML, and XSLT in the last couple of weeks. I’m using some of these tips in a document I’m creating (Club Diary). Exported XML from Access, importing and applying an XSLT with aid: tags present to define character styles in a table.

    I do have a couple of questions:

    1. Do you have to specify a number of rows (in aid:trows=”xx”)? As the data coming from the database could contain any number of records (and therefore rows) it would be preferable to not have to specify a number in this attribute.

    2. When importing XML and a blank field is encountered, is it possible to not display the field placeholder and remove the blank space between lines?

    Cheers,

    Paul

  29. Cari Jansen says:

    @Dan I’m not sure how InDesign manages attributes, as far as I’m aware they import ok, but on the layout side out-of-the box there’s nothing really that would happen as far as I know. But as @locavore mentions you can basically do anything with the XML on import or even after import to make it behave differently to what InDesign can do out of the box. Either by running an XSLT, which could turn attributes into elements that InDesign can read/format or even by developing some JavaScripts that interact with the XML and apply certain additional formatting controls, placements etc. (I generally outsource the Javascripting side of things, build the templates, review the XML and then consult — Cari

  30. dsoileau says:

    Hi Cari,
    Yes, my question is about adding multiple unique attributes to a tagged element (span) via the Structure pane. Experimentation revealed that a space between values works, though I’m not sure about why that works. Any insight into how the attributes are managed by InDesign would be appreciated.
    Dan

  31. locavore says:

    @Dan: did you try entering “class” as the attribute name and then two words separated by a space for the attribute values. i.e. “italic text-indent” (without the quotes)? This works for me in IDD CS5.5 using the Attributes dialog.
    If you are using a DTD then both the attribute name and the attribute values must be valid. It looks like you are imitating HTML syntax, in which case the class attribute and free-text values for it are OK. For example:
    <Story>
    <p class=”h1 title article”>A title</p>
    <p class=”body no-indent”>A paragraph with an inline <emphasis class=”italic”>emphasis</emphasis> and <keyword class=”bold italic keyword”>keyword</keyword>.</p>
    </Story>

    You could remap this with XSLT during export to achieve HTML like this:
    <div>
    <h1 class=”title article”>A title</h1>
    <p class=”body no-indent”>A paragraph with an inline <em class="italic">emphasis</em> and <b class="bold italic keyword">keyword</b>.</p>
    </div>

    It is pretty easy to map from a paragraph or inline XML element to similar HTML elements. If you need to make complex groups of content into nested divs, you will probably need more complex XSLT for your grouping. Note that if you want to build a complete HTML file from InDesign content, you have to define the html, title, and body elements in the XSLT and then you need to determine how to handle each separate text flow that you have tagged in the InDesign file, whether it should be in its own div in HTML or not.

  32. dsoileau says:

    Hi Cari,
    In my InDesign document I have a span element that requires an attribute named class with two values: “italic” and “text-indent”. But InDesign won’t allow me to have two attributes identically named, and both require the same name (class). Is it possible to enter multiple values in the Edit Attribute dialog box value field for a single class attribute? If so, what is the separator?
    Thanks,
    Dan

    • Cari Jansen says:

      Hi Dan,

      I’m not sure what tag in the structure panel you are trying to add an attribute to, but you can add multiple attributes to a tag when setting up structure for XML in InDesign. What you can’t do is add two attributes with the same name. Are you applying the attributes via the Structure pane?

      Cari

  33. mawa_73527 says:

    Hi,

    I am looking for a way to format column width other than using points. I am looking for a way to have the columns withs in tables to be relative like in SGML 1* or 2* or even 1.7* and I would want to mix this with fixed widths e.g.:
    first col be always 100 points; second col be relative 1; third col be relative 2; and last be 80 points.

    Can indesign compute this if the width of the table is known?

    Matthias

    • Cari Jansen says:

      Hi Matthias,

      You’d need to run an XSLT on import that calculates this for you. E.g. if you know in advance what the overall width of the table would be, and you’ve got ‘proportional’ settings e.g. Column 1 20%, Column 2 40% etc. you can get your XSLT to convert this to points during InDesign XML import.

      Alternatively, you could run a script that processes columns proportionately to the width of the parent text frame they appear in.

      – Cari

  34. Cari Jansen says:

    Pleasure @SSHunho I think you’ll most likely need to customise with scripting for object style level support. – CJ

  35. sshunho says:

    Hi Cari,

    Many thanks for the articles. I’ve learned a lot about InDesign XML attributes and InDesign Namespaces. This is really useful.

    Just a quick question. Does InDesign XML support Object Styles as it is with Paragraph and Character style attributes? Is there anyway I could include object style in the XML?

    Thanks again!

  36. Kurtis says:

    Very useful! Thank-you.

  37. Jamie says:

    The tag got removed from the comment. I wanted to say that the tag does not have to be named “Image” for InDesign to expect linked images.

  38. Jamie says:

    Worth pointing out that images don’t have to be linked using a tag named “”. InDesign will assume the href attribute of any tag is for an image.

  39. Sunny says:

    I have an XML file with table and I have converted this table to CALS table and added indesign style through XSLT. Unfortunately, the styles are not applied when the XML is improrted to Indesign. Can any one suggest a solution pleae?

  40. Claudino says:

    Hi Cari,
    Thanks lot for this article!

    I have a related problem that made me google for hours and still not found any answer.

    I have Indesign tagged tables that I’d like to export to xml, but I need them without the “aid:” elements. When I untag all the text in a table, it exports fine, but when I tag any paragraph or other element inside that table, the “aid:” arise, and the final xml should’t have them. Is this possible?

    Thanks in advance
    Claudino

  41. loic says:

    Hi Cari,

    Thx for your answer. It’s really encouraging :)
    A script ? You should keep in touch with marc who should really enjoy such a project ;)

    A+ Loic

  42. Cari Jansen says:

    @Loic,

    Yes XML means you don’t need to work with everything inline to get EPUB content in the correct order.

    It is by no means perfect, but it does mean that hypothetically speaking you wouldn’t need to redesign your publications for EPUB output if they already exist in for print-layout purposes.

    But I must be honest and say that practically speaking it is often quicker to build an inline document.

    A way around that would be for someone to develop a script that could assist in building the XML structure. A script for instance that recognises groups and inserts those as ‘nested’ tags :-)

    The script I think would also need to review the default ‘tagging’ order when we use ‘AutoTag”. :-)

  43. loic says:

    @Cari,

    Yes, I heard about XML/epub relationship but never really played with it. Waiting for your next post so it can answer one of my questions ie does using xml tagging avoid setting an unique flow (anchored objects etc…) or is it just for ordering contents ?

  44. Cari Jansen says:

    @Loic, Merci beaucoup pour les mots gentils!

    XML can also be used for EPUB creation. a) you can control which content is going to be included in the EPUB through the Structure inclusion and b) you can control the order in which it will appear in the EPUB.

    I hope to do a write-up about that at some point, have so many other things to do at the moment :) Just need more hours in the day :-)

  45. loic says:

    Yes, this one rocks !!! Set styles on XML structure is very promising :)

Leave A Reply