Brisbane Handout

8
IDUG Brisbane, Qld 14 August 2008 XML & InDesign Cari Jansen cjansen@typefi.com

Transcript of Brisbane Handout

Page 1: Brisbane Handout

IDUGBrisbane, Qld14 August 2008

XML & InDesign

Cari [email protected]

Page 2: Brisbane Handout

© 2008- Cari Jansen XML & InDesign –IDUG, Brisbane, Qld 2

How To – Build an InDesign XML run-in template for repeating elements

Let’s have a brief look at an example and how you could develop an InDesign template for automated XML run-in of repeating elements.

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

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

Figure 2. Adding an element to the Structure.

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.

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

Page 3: Brisbane Handout

© 2008- Cari Jansen XML & InDesign –IDUG, Brisbane, Qld 3

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.

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.

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

Page 4: Brisbane Handout

© 2008- Cari Jansen XML & InDesign –IDUG, Brisbane, Qld 4

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

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

Continue to do this until you’ve completed the tags. 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 sentence “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.

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 you 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 pane.

Page 5: Brisbane Handout

© 2008- Cari Jansen XML & InDesign –IDUG, Brisbane, Qld 5

Sample XML

<?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>

Page 6: Brisbane Handout

© 2008- Cari Jansen XML & InDesign –IDUG, Brisbane, Qld 6

Additional Notes

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 Styles from 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.

Figure 9. XML tags mapped to similarly named paragraph styles.

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.

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 href=”file://Volumes/DOCS_IMAGES/2008_Sydney/IMG_1806.JPG”></Image>

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

Image reference examplesImages 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 youre connected to.

Tables

Tables in InDesign CS3 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:

Attribute Descriptionaid: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.

Page 7: Brisbane Handout

© 2008- Cari Jansen XML & InDesign –IDUG, Brisbane, Qld 7

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

Figure 11. Example of InDesign Table in XML format

Note that a table can not 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 Table element.

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

Figure 12. 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 Descriptionaid:pstyle Paragraph Style formatting

aid:cstyle Character Style formatting

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 adult life ... until he encountered Impressionism and Neo-Impressionism in Paris.</body>

Figure 13. Example pstyle and cstyle attributes used in XML.

Exporting XML

One of the reasons you might be asked to export XML from InDesign is for the purpose of reusing the content in your document for other media, such as web or mobile devices. For XML to be exportable from your InDesign document, the document content must be ‘tagged’.When the document was created as part of imported XML workflow, those tags will already exist and the Structure pane will provide a good indication of which content is marked up in the document. However, when the InDesign document was created without any use of XML, you’d have to create this structure and markup content with Tags yourself.To make the tagging easy, consider mapping used Styles to Tags. This will result in automatic tagging of content.To map XML styles to tags, select Map Styles to Tags from the Tags panel menu or the Structure pane menu. The Map Styles to Tags dialog appears. All Paragraph, Character, Table and Cell Styles available in the document are listed under Styles. The Tag menu provides a drop-down menu next to each Style that contains a list of all Tags to which Styles may be mapped.To automatically map matching Style and tag names, click Map by Name. All matching names are automatically linked up. For any Styles not mapped, you can choose an alternative mapping option from the Tag drop-down menu.One thing to check before exporting XML from the InDesign document is that the tagging order is correct. Enabling the Show Text Snippets option from the Structure pane menu will display text fragments, making it easier to recognise the order content in the Structure pane.To reposition one or more elements to another position in the Structure pane, select the elements and click and drag them to their new location. The structure you create will be represented in the exported XML.To Export XML, select Export XML from the Structure pane menu. Alternatively select File >

Cross-media Export > XML or File > Export then select XML as format.

Page 8: Brisbane Handout

© 2008- Cari Jansen XML & InDesign –IDUG, Brisbane, Qld 8

Resources and References

These web resources will explain the structural rules for XML as well DTD, XSLT and XPath. To teach you all about XML goes well beyond the scope of this 45 minute IDUG-session. If you’re keen on learning more, a good starting point would be to use the following web-resources.

Web Resource URLExtensible Markup Language (XML) http://www.w3.org/TR/xml/

XML Tutorial www.w3schools.com/xml/

DTD Tutorial www.w3schools.com/dtd/

XSL Tutorial www.w3schools.com/xsl/

Other resources available online

(2008) Adobe Systems. Adobe InDesign CS3 and XML: A Technical Reference, available from http://wwwimages.adobe.com/www.adobe.com/products/indesign/scripting/pdfs/indesign_and_xml_technical_reference.pdf

(2006) Blatner, D & Kvern, O.M. Transform XML with XSL, Excerpt from Real World Adobe InDesign CS2, available from http://www.adobe.com/designcenter/indesign/articles/indcs2at_xsl.html

(2004) Miller, D. Adobe InDesign and XML, available from http://www.xml.com/pub/a/2004/08/04/indesign.html

There are many, many books available on and about XML, XSL, DTD. The following are some of the resources you can find on my bookshelf.

Further Reading(2004) Harold E.R. & Means W.S., XML in a nutshell. Third Edition, O’Reilly

(2003) Holzner, S., Real World XML, Peachpit Press

(2007) Hoskins, D.J., XML Publishing with InDesign CS2+, O’Reilly

(2007) Maiwdvald, J.J & Palmer, C., A Designer’s Guide to Adobe InDesign and XML: Harness the Power of XML to Automate your Print and Web Workflows, Adobe Press

(2003) Ray, Erik T., Learning XML, Second Edition, O’Reilly Media