Fan of creative technology, elearning, instructional design and a little geeky

Adobe InDesign and XML: Building a run-in template

Some years ago I ran a series of seminars on working with XML and InDesign using an ‘out-of-the-box’ approach. I put together some notes at the time, and I recently rediscovered them and thought it was time to share them with the rest of the world 🙂  I’m posting them un-edited, so if you spot any glaring errors feel free to send me an email or leave a comment, and I’ll update the  posts accordingly.

Figure 1 - XML tagging example.

Figure 1. Reviewing the structure of a design and assigning tags to content.

Building an InDesign XML run-in template for repeating elements.

The design

Give your data meaningful names, in the Tags panel you’d add new tags for each of the XML elements. Consider using a DTD – Document Type Definition, to quickly insert all of the possible tags into the Tags panel without making any typos. DTD’s also enable you to validate the XML structure you create, or that is imported during XML import, against rules set in the DTD. For example a rule could be that a Dealer may must have nested elements for brand name, description, office details, phone listed in a fixed order.

If you are going to Map Tags to Styles as part of your template design, it is probably a good idea to create matching Tag and Style names in the template, as it makes adding the Tags to the panel a much easier task.

Building the structure

With the design element finished, you’re ready to get started with the build of the Structure and template.

If preferred, select the original Root tag in the Tag panel and rename it to your preferred name. The new name automatically updates the Root element name in the Structure panel.

To view the Tags panel, select Window > Tags. Double click the Root tag and rename it

One thing to keep in mind is that the XML list of car-dealers, when imported, will end up as text in a Text Frame. The default tag for a Text Frame or series of threaded text frames (a story) in case of a multi page or listing, is… you guessed it… the Story tag. This tag is a child tag, which means it is nested within the root tag. In the Structure panel that is indicated by the indentation.

The Story element itself will be the parent of all other elements. When you are basing the development of the InDesign run-in template on a sample document you’ve created, you can automatically add the Story element to the Tags panel and tag the Text Frame – instead of first adding a new Tag to the Tags panel, then adding this element to the Structure.

Figure 2. Adding an element to the Structure.

Figure 2. Adding an element to the Structure.

Automatic Tagging

Why tag things manually when we can do things ‘on-the-fly’ right? Select the Text Frame containing your single car dealer design content, and click the Autotag icon at the bottom of the Tags panel, or select Autotag from the panel menu.

Figure 3. Auto Tag Story

Figure 3. Auto Tag Story

The Story Element is automatically added to the Structure panel and the Text Frame is now tagged.

If the Tag that’s added carries another name, then the default tag for Stories has been changed for the document you’re working on. To verify InDesign’s four default tags used for Story, Table, Cells and Images, select Tagging Preset Options from the Tags panel menu.

Figure 4. InDesign’s default Tagging Preset Options
Figure 4. InDesign’s default Tagging Preset Options.

Ok, we’ve added one tag, but what about the rest of the XML elements that need to be inserted?

New tags

At this stage the Tags panel displays only the DealersList and Story tags. We need to add quite a few additional tags.

When you’re working with repeating elements, as is the case in this example, you would add a Tag to your Tags panel for the element that is the repeated element. In this example that is the dealer element, as you are going to use this template to run-in a list of all of the individual dealers for different brands of cars.

Figure 5. Tags panel
Figure 5. Tags panel.

To add a new tag for the dealer, select New Tag… from the Tags panel menu or click the New Tag icon at the bottom of the panel. Name the Tag “dealer”.

Importing a DTD

I just remembered… isn’t it easier to use a DTD to add all the tags to the InDesign file? Rather than choosing the New Tag command each time, to insert a new tag? Absolutely! So let’s add the remainder of the tags used in this example by importing a DTD. Assuming you have a valid DTD available, select Load DTD… from the Tags panel menu and navigate to the .DTD file and click open… and all of the tags defined as part of the DTD are available.

An easy way to build the rest of the structure for your template and mark-up your template is to highlight content, then apply a tag.

Applying tags

First we need to highlight all of the content of the repeating element you’re working on, next click the repeating element tag (dealer) in the Tags panel to apply it.

Figure 6.

Figure 6. Applying the repeating element tag to selected content.

The element will automatically nest below the Story element.

Next, based on the notes on which tags are going to be assigned to what text in your sample, highlight each of those components. I often work in the story editor when doing this as it much easier to see the tags that are marking up your sample content. To see the tags in the Story Editor ensure the Show Tag Markers is enabled from the View > Structure. Also enable Type > Show Hidden Characters, as it is easier to see if you have paragraph returns and other hidden characters selected when you are building your InDesign template.

Remember that your XML does not include paragraph returns and if you want the XML to run-in and replace some of your dummy text, it’s probably best to exclude the paragraph returns when selecting text to be marked with a tag. Doing so will ensure that during run-in those paragraph returns are inserted as per their position in the template.

Figure 7. Applying a tag to selected

Figure 7. Applying a tag to selected content.

Next you’re ready to continue marking up the rest of the text, in the story editor highlight the bits of sample text that are part of the template design and click the matching Tag in the Tags panel.

Continue to repeat this tagging process until you’ve completed the markup of text. Any text that needs to automatically be inserted as a prefix or suffix of a Tag, must be placed fully outside the tags. In my example that is the text “your local dealer” and the prefix ‘Phone:’

Once completed, you can replace the sample text with more relevant text for the template.

Figure 8. InDesign template design completed and ready for import of XML.

Figure 8. InDesign template design completed and ready for import of XML.

Import XML

You’ve now created a working InDesign template and can test it with some sample XML. To test the repeating elements function, create a small sample XML file that is extracted from the longer one and Import the XML, then review if you need to make any changes to your template.

To import XML, select File > Import XML or select Import XML from the Structure pane menu.

Ensure that you enable Clone repeating text elements in the XML Import Options and Do not import contents of whitespace-only elements options, and if you only want to import elements that match the structure you created in your template enable this setting as well.

If  the XML file you’re importing contains a reference to an XSLT or if you’ve been supplied an external XSLT you can apply this during import as well.

Most often XSLTs are used to transform any kind of XML to XML that is conform specified requirements. It can leave out elements from the source XML that are redundant and it can be used to sort XML content during import. For instance, in the scenario above, you might want to sort the XML by brand name during import.

Validate XML

Because we imported a DTD earlier as part of our template, we can validate the XML we’ve imported against this DTD.

To validate XML against a DTD, select Validate from the Structure pane menu. Validation can be applied from the Root element, which is the top-most element or from any selected element.

Where validation fails red markers flag invalid Elements in the Structure and a list of validation errors with suggested fixes is listed at the bottom of the Structure panel.

Code Sample
<?xml version=”1.0” encoding=”UTF-8”?>
<DealersList>
<Story>
<Dealer>
<BrandName>Alfa Romeo</BrandName>
<SubTitle>Visionary innovation meets exhilirating performance</SubTitle>
<Description>Alfa Romeo is an Italian automobile manufacturer founded in 1910. Alfa Romeo has been a part of the Fiat Group since 1986. The company was originally known as A.L.F.A., which is an acronym for Anonima Lombarda Fabbrica Automobili (translated: Lombard Automobile Factory, Public Company).</Description>
<Office><DealerName>Alf Barbagallo Motors</DealerName>, 354 Scarborough Beach Road, Osborne Park WA 6017</Office>
<Phone>08 9231 5999</Phone>
</Dealer>
<Dealer>
<BrandName>Audi</BrandName>
<SubTitle>Text here</SubTitle>
<Description>Text here.</Description>
<Office><DealerName>dealers name here</DealerName>, Name, Address here</Office>
<Phone>00 0000 0000</Phone>
</Dealer>
<Dealer></Dealer>
<Dealer></Dealer>
<Dealer></Dealer>
</Story>
</DealersList>
Similar posts
  • 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 [...]
  • 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 [...]
  • Adobe: the Founders’ Perspective. Adobe changed the world and revolutionized the publishing industry. A must watch computer history video for anyone who has a passion for the big red A. John Warnock and Chuck Geschke presenting… ‘the founders’ perspective’. Chuck: “When someone tell you our products have made a difference in their life, in their work, their creativity… that [...]
  • 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 [...]

22 Comments

  1. Maarten Maarten
    October 24, 2013    

    Hi Cari. Hope you can help: I’m creating a brochure with more than 200 pages. And i have a XML-file per page. Now i want to have a template where i can create a page and link a specific XML-file to that page by merging the content. I that way all the elements on that page can be automatically styled. And than create another page in the same document and link another XML-file for that particular page. But as I understand it, there can be only one XML-file per Indesign-document. Am i right?

    • October 25, 2013    

      It’s quite likely you’ll need to customise your xml import through some scripting. You can import more than one XML file into an InDesign file. You can ‘append’ to existing XML. However depending on the product that you’re working on this might not be something you can do out of the box. I’ve done some work last year with a client who required insertion of multiple XML files from which data was to be extracted and run in… I ended up working with a developer who build a customised import xml plug-in for us.

  2. September 12, 2013    

    Hi, hope you can help. Im trying to make a hyperlink as part as a XML-file and import into indesign. But the link doesnt seem to work. I have trying , , , . But it dosent work.

    I want some text to be clickable in our online catalogue – but I cant figure out how I can get the hyperlink to work.

  3. Charles Cooper Charles Cooper
    February 2, 2012    

    Hi Cari,

    I’ve been trying to import an XML table into ID 5. It works just fine with one significant exception – any images in the table are lost on import.

    If the image is outside of the table, it works fine. It appears to be an ID problem.

    Have you ever been able to import an image in a table cell?

  4. November 12, 2011    

    Thanks @ Paul.

    XML can only have ONE Root Element, you’ll have to build the repeating elements within this. What is it you are trying to achieve? If you need items to start on a particular master-page design, you might need to add an XML Run-In Script to your XML run-in that handles this part of things.

    XML Output can be altered, by using XSLT during import, so you can format it to work better in InDesign as well.

    – Cari

  5. November 12, 2011    

    Very helpful tutorial, many thanks.

    However, I have run into a problem: I’m trying to set up a similar template to the example you have here but find I don’t have enough tag levels in the XML (i.e., imagine this same structure but without the “DealersList” tag). In other words, I need the repeating element to be the root element, which InDesign is not allowing me to do.

    I can edit the XML text file and add a simple “Root” tag at the start/end and it works beautifully, but I’m afraid our XML output is automated and cannot be altered. Any insights?

    paul

  6. September 18, 2011    

    @Mike

    Pleasure.

    Glad XML/InDesign is helping you out with tedious task. Although especially InDesign’s XML tables add a lot of overhead to the XML (for long documents it can therefor take a while to import the XML I find)… it still beats having to format things manually 🙂

    Next step is to look at fully automated pagination… using InDesign Server 🙂

  7. September 18, 2011    

    @Naga

    You are welkcome.

    Some XML Editors have the ability to generate DTDs from sample XML you create. But you can write them from scratch as well. You can start at w3schools: http://www.w3schools.com/dtd/default.asp to learn more about DTDs and there are plenty of good books and online sites out there as well to help you along.

    Cari

  8. September 11, 2011    

    Thanks Cari! I work as a graphic designer at a medium-sized web-publisher company and part of my job is the rather tedious task of maintaining the changing values inside of 400+ media kits that we show to potential customers. I’ve been searching for a solution to re-vamp all 400+ inDesign files so that in the future I won’t have to scan through the documents, manually change each text frame (sometimes it’s like 20 different bits of copy), and then do it all over again a month later for each doc when the data changes. Up until a month ago, I was oblivious to the task that inDesign might be capable of such functionality. I got curious and found your tutorial. THANK YOU!! You just helped me save a ton of time and mundane work. Great post!!!!

  9. Naga Mohan Naga Mohan
    September 7, 2011    

    Thanks Cari, for the tutorial.

    1) How to create a DTD file?
    2) If I have an Excel file how to create XML file like the one ‘sample code’ you gave above.

    – Naga

  10. August 28, 2011    

    How to proces xml to indesign plz
    give step by step procedure

    Thanks

  11. dosch dosch
    March 18, 2011    

    thank’s for this tuto, I’m discovering indesign xml solutions and data merge, but I can’t yet see their differences. Couldn’t have we done this tuto with data merge?

    thank’s for your answer

    • March 21, 2011    

      Hi Dosch.

      Data merge works different from XML, in that you must create content insertion points prior to the content run-in. For XML that isn’t required. For instance in book publishing, you wouldn’t know the exact order in which headings, subheadings, body copy, first para full-out etc. would appear, yet with XML run-in you can insert these in any order (that is if a DTD doesn’t forbid this…) and data is formatted based on Tags to Style mapping instructions as it populates pages.

      In the example I gave you could use data merge if the dealer entries are always the same length. You’d have to lock in how-many you’d fit on the page in other words. However, with XML run-in it will run in as a continuous story flow. In Data Merge each dealer would be a ‘stand-alone’ item in a fixed position.

      Hope this helps explain the difference a little bit more.

      Cari

  12. March 7, 2011    

    @Nnamdi

    You’d need to ensure that your template contains ‘threaded text-frames’. That way you can continue to run-in new ‘objects’. It’s a bit of a work-around, but the content will run-in as a single thread. An alternate you can look at maybe is InDesign’s Data Merge for automated import into templates… this also supports XML.

    To answer your last question: Yes it is. You can do different things.

    Either ensure the item is exact size and then set-it up as part of your repeating elements as an inline/anchored object. Alternatively — and this is what I recently did for one of my clients — build a font for the icons so you can incorporate the icon inclusion with the text.

  13. Nnamdi Nnamdi
    March 6, 2011    

    Hi cari, thanks a lot for the tip, was begining to loose my mind makind different attempts to get text frames to repeat when import XML. So I guess indesign doesn’t do that yet.

    Another question if you dont mind. Is it possible to get a small icon repeat with the paragraph rule and move along with the text when d document flows down or up!

  14. March 4, 2011    

    @Nnamdi,

    Thanks for your message. I’m guessing you are referring to the pink background behind the ‘brandname’. That is actually not a text-frame, it is a Paragraph Rule that is applied to the paragraph style.

    see the following tips on my site for more info:
    http://carijansen.com/2007/09/01/tip-057/
    http://carijansen.com/2009/10/18/tip092/

  15. Nnamdi Nnamdi
    March 3, 2011    

    Hi Cari,

    Great work!

    I am new to xml and indesign. Are you able to make the text Frame (the Pink curved edget Graphic) which contains the brand name repeat. I have tried and tried with no luck. I am trying to automate a publication where some headings are in styled text Frames.

    is this possible?

    Regards.

  16. February 24, 2011    

    No never used xsl:sort() so far. Most of the time I just use the basics and complain about how tough this is to simulate functions 😉

  17. February 24, 2011    

    @Michael Pleasure. Feel free to translate it into Dutch and publish in NL-IDUG Mag as long as it has a credit, no problem with me. I’ve got more that I want to upload the coming days. But been a little busy…

  18. February 24, 2011    

    @Loic, Thanks 🙂 You’re welcome. You’d need to use XSLT for transforming XML in import or export. Have you worked with the xsl:sort ? It used to give some weird error in InDesign. I’ve not looked at XSLT for a while to be honest 🙂

  19. February 24, 2011    

    Nice entry! Do you have a dutch version as well? I’ll trade you with a #broodjekroket. All joking aside, very nice work!

  20. February 24, 2011    

    Hi Cari,

    Thanks for your tutorial. Always good to review the basics :D. I understand better the need for DTD’s (create tags at the first place and of course validation). Thanks to your former PDF, I also discovered auto tagging.

    It’s great that people like you share this kind of knowledge 🙂

    FWIW, I worked on a project where XSLT allowed not only to reformat XML but save considerable processing time by shortening nodes to be considered according to certain attributes. Can DTD do the same ?
    ie:
    <tag consider="true"> <!–consider this tag–>
    <tag consider="false"> <!–ignore this tag–>

    thx again 😉

Leave a Reply

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