Indcs3ip Xmlrules
Indcs3ip Xmlrules
A Technical Reference
TABLE OF CONTENTS Adobe® InDesign® CS3 enables the design and production of professional page layouts.
1 Overview of XML syntax Built for demanding workflows, InDesign integrates smoothly with the Adobe tools you
2 Integrating XML into a publishing workflow use every day, streamlines repetitive tasks, reliably outputs pages, and offers powerful
4 XML tagging features in I nDesign features for creating richer, more complex documents. Additionally, InDesign CS3 has
10 Planning an XML workflow extensive XML and scripting capabilities to better support the varied needs of today’s
multichannel publishers.
11 Importing XML files
17 Formatting XML text content manually Combining the predictable structure of XML files with InDesign’s page layout capabili-
18 Formatting XML text using style mapping ties lets you automate design and production tasks. You can associate InDesign format-
18 Using Find/Change to format XML text
ting with XML content, so that when you import an XML file, content is automatically
laid out on your pages. If you lay out many documents that have similar formatting,
19 Formatting text using namespace attributes
in import and export
you can set up your design for the first document and then automate subsequent
publications.
23 Using anchored objects for repeating
elements XML also serves as a useful interchange format to move information among different
24 XML rules applications. For example, if you create content in InDesign that will be published in
27 Exporting XML other media (such as on the web), you can export the InDesign file as XML to reuse the
28 Using InDesign Interchange (INX) files in content.
XML workflows
Together, the powerful layout engine in InDesign and the inherent benefits of XML
28 Where to go from here
structures let you establish a publishing workflow that reduces production effort with-
29 Appendix A: XML syntax out compromising your design standards.
31 Appendix B: InDesign-to-XML
character mapping This white paper assumes an intermediate level of XML knowledge and provides de-
tailed technical information about XML support in InDesign CS3.
<?xml version="1.0"?>
<Article author="CJM" date="2008-07-17">
<Dateline>Anytown, Anywhere</Dateline>
<Title>Traffic is Worse than Ever</Title>
<Para>Complaints about traffic are on the rise. A recent survey shows
that commuting time is increasing.</Para>
...
</Article>
Like Hypertext Markup Language (HTML), XML uses angle brackets to indicate
markup tags (for example, <Article> or <Para>). HTML has a predefined set of tags;
in XML, you describe content more precisely by creating custom tags. The preceding
example uses descriptive tags, such as Article, to label the information.
For more details about XML syntax, see Appendix A on page 30.
Integrating XML into a publishing workflow
XML is widely used for data exchange, such as e-business transactions. For creative professionals, PDF versus XML
who mainly work with content, XML is also becoming a critical technology. XML provides some PDF and XML support the publishing workflow in
exciting new opportunities for your publishing workflow: different, but complementary, ways. PDF is designed
to preserve the exact appearance of a document
• Layout automation. When the content structure is predictable, you can automatically process from one medium to another. PDF documents can
be printed without reformatting. A PDF file may also
it to produce a consistent look and feel in your final output. For example, you can import
contain structured information, enabling it to adapt
XML into I nDesign and lay out documents automatically. You can also export content from to different display devices and to interact with XML
a database file to XML, and then use the XML file to produce the final content (for example, workflows. XML preserves the structure, but not the
to publish a directory). To ensure that content is organized consistently, you can define the appearance, of content, as well as metadata about
required structure using a document type definition (DTD) file. elements. XML is easy to edit and can be displayed
differently for different viewing media, making it an
• Reusing content. You can use XML as an intermediate format to exchange information between excellent choice when you need to share content that
otherwise incompatible applications. This process lets you reuse information without tedious will be edited or reprocessed into another output
format.
manual reformatting. XML provides extensive support for metadata, so you can provide
additional information about your document and about elements within the document.
The following sections provide more detail about how InDesign supports XML-based publishing.
If the information you need to publish is stored in a database, you can export from the data-
base to XML, and then import the XML file into InDesign, where InDesign formats the content
automatically.
InDesign
<XML>
Database
When publishing from a database, you often have a structure pattern that needs to be laid out
identically from page to page. InDesign lets you define the page layout once, and then clone that
layout for additional information. You can set up your layout using sample content or a typical
set of information and then repeat that layout as many times as required for all of the content.
For details on cloning layouts and other XML import options, see Importing XML files on page 11.
XML file
Title Sample Upside Down Chocolate Cake
<Recipe>
Ingredients
<Category>Desserts</Category> Ingredients
• SampleIngredients • 1 cup Flour (all-purpose)
<Recipe_Title>Upside Down Chocolate
• SampleIngredients • 1 ¾ cup Sugar
Cake</Recipe_Title>
• SampleIngredients • 1 cup Brown sugar
<Ingredients>1 cup Flour (all-purpose) • SampleIngredients • 2 tsp. Cocoa
1 3/4 cup Sugar • SampleIngredients • 2 tsp. Baking powder
1 cup Brown sugar • SampleIngredients • 1 sq. semi-sweet Chocolate
2 tsp. Cocoa • SampleIngredients • 2 tbsp. Butter
2 tsp. Baking powder • ½ cup Milk
Instructions Sample. Instructions Sample. Instructions Sample In-
1 sq. semi-sweet Chocolate structions Sample. Instructions SampleInstructions SampleInstruc-
• 1 tsp. Vanilla
2 tbsp. Butter tions SampleInstructions SampleInstructions SampleInstructions Mix flour, 3/4 cup sugar, and baking powder and place in a Py-
1/2 cup Milk SampleInstructions SampleInstructions Sample rex dish. Melt 1 square chocolate with butter, and milk until thick.
1 tsp. Vanilla</Ingredients> While hot, add vanilla and then pour over first mixture. Bring 1
<Instructions>Mix flour, 3/4 cup sugar, 3/4 cups water, 1 cup sugar, 1 cup brown sugar, and cocoa to a
and baking powder and place in a Pyrex boil. Pour over mixture in Pyrex dish. Bake at 375° for 40 minutes.
dish. Melt 1 square chocolate with butter, Serve with whipped cream.
XML file with repeating structured content Tagged InDesign layout Page design and formatting can be cloned automatically.
Use a DTD to validate the structure of your imported XML. On the left, the DTD identifies an error for you to
fix—the Notes element must occur before the Number_of_Servings element. On the right, the structure is valid.
Structure rules are stored in a Document Type Definition (DTD). The structure rules need not be
rigidly defined. For example, a DTD could declare that a recipe must have pictures or a bulleted
list, but it can also specify that these items are optional. With InDesign, an imported XML file
can specify the DTD, or you can load it into a document separately. Once you have associated
a DTD with XML content, you can validate the content. Alternatively, you could use an XML
generation and editing application to do this validation separately from InDesign. In addition,
InDesign does not require you to use a DTD, so you can also work without validating.
<Newspaper>
<story author="CJM" editor="SSO">story goes here</story>
<story author="MDM" editor="SSO">story goes here</story>
Adobe InDesign CS3 and XML: A Technical Reference 3
</Newspaper>
Metadata is embedded at the location of the content it refers to as an attribute of that content,
ensuring that it always stays with the described element. Later, you could use the metadata to filter
information; for example, to locate all of the stories a particular author has written.
InDesign provides additional support for metadata in any InDesign file with the Extensible You can find additional XMP resources at
www.adobe.com/products/indesign/scripting
Metadata Platform (XMP) standard. The XMP standard, created by Adobe, lets you store docu-
ment information, such as the author, copyright information, and keywords, in a file. The XMP
information is accessible to other users even if they do not have the application in which you
created the file. All Creative Suite 3 applications automatically embed certain XMP metadata.
For example, InDesign files include XMP metadata about the swatches and fonts used in a docu-
ment, as well as any linked files. You can view, search, and edit metadata using Adobe Bridge
(available from any CS3 application). You can also embed metadata in InDesign files by choosing
File > File Info and editing or adding metadata. The XMP metadata is saved as XML in a special
section of the application file.
Use the Structure pane and the Tags panel to work with XML structure in InDesign. The
Structure pane shows you the document structure and lets you make changes to it. The Tags
panel lists the XML tags that are available in the document. Just click the tag you want to apply it
to selected content. (If you don’t want to tag items manually, you can use the automated tagging
techniques described later in this document.)
Add an attribute
Validate Add an element Structure menu
The Structure pane and Tags panel give you control over XML content. To display the Structure pane,
choose View > Structure > Show Structure. Choose Window > Tags to open the Tags panel.
In contrast to this, an XML file consists of elements, attributes, and text. An XML file does not
usually provide any font, page positioning, or other formatting information. You must specify
how you want XML content to flow into your InDesign document.
An XML document is required to have a single root element. The root element contains all of
the elements in the document, and is shown near the top of the Structure pane. In the art in the
preceding section, the root element is Recipe.
You can associate XML with different InDesign objects. Most often, you associate XML with
stories, paragraphs, text ranges, graphics, and other media. When an XML element is associated
with a text frame, InDesign tags any frames that are linked to that text frame.
You can also set your text frames to indicate the tag they are associated with by choosing View >
Structure > Show Tagged Frames. InDesign displays the frames in the document window with a
background color, which matches the color for the tag in the Tags panel.
For text frames, tables, and table cells, InDesign lets you specify the tags to be used when InDesign
automatically tags those objects. If you tag a range of text or other item in an untagged story,
InDesign tags the story automatically with the default text frame tag. Similarly, if you tag some text
inside a table cell, InDesign tags the table cell, table, and containing story using the specified tags.
1 In the Tags panel menu or the Structure pane menu, select Tagging Preset Options. By default,
text frames are mapped to the Story tag, tables are mapped to the Table tag, and table cells are
mapped to the Cell tag.
3 Select a text frame, table, table cell, or image and then click the Autotag icon ( ) in the
Tags panel.
You don’t have to select paragraphs one at a time and tag them if you’re using paragraph, char-
acter, and nested styles. Instead, you can map style names to tags, so InDesign can automatically
tag the specified content.
In addition, if you can control style names or tag names, consider matching them so that you
can automate the mapping process. For example, if your XML content has a Caption tag, you can
create a matching Caption style in your document. The Map By Name button lets you associate
Adobe InDesign CS3 and XML: A Technical Reference 5
those styles automatically.
To assign tags automatically using style mapping:
1 In the Tags panel menu (or the Structure pane menu), choose Map Styles to Tags. The Map
Styles to Tags dialog box opens.
2 For each style you want to map, click the Tag list to display a pop-up menu and choose the
appropriate XML tag from the list. If your style names match the XML tag names, click Map
By Name.
Note: To use mappings you set up in another I nDesign file, click Load and select the file.
3 Specify whether you want to map styles that occur in special locations by checking the appro-
priate items.
4 Click OK. The new XML tags are applied throughout the document.
1 Click the Structure pane menu, and then click Load DTD.
Note: When you load a DTD file, it is embedded in the InDesign file (not linked). If you make
updates to the DTD file, you must reload the DTD into InDesign.
3 Click Open.
I nDesign checks the DTD as it is loaded. If any problems are found, InDesign displays an error
message. To correct errors, open the DTD in a text editor, make the appropriate changes, and
then try loading it again.
2 InDesign reports any structure errors at the bottom of the Structure pane and provides sug-
gestions on how to fix the problem. Click a suggestion to try that correction. When InDesign
identifies invalid structure, it displays a warning icon on the element icon and highlights it in
red in the Structure pane.
When the document is valid, InDesign tells you that no validation errors were found.
1 In the Structure pane, right-click (Ctrl-click for Mac OS) the element that you want to add an
attribute to and then choose New Attribute from the pop-up menu.
2 Specify the name and value of the attribute, and then click OK.
The new attribute is shown underneath its element in the Structure pane.
Note: Some attributes, such as table and image attributes, are created automatically when you
export content to XML. You do not need to define these attributes in the Structure pane. For more
information, see “Table attributes” on page 21 and “Images” on page 9.
To edit an existing attribute, double-click the attribute in the Structure pane, make any needed
changes, and then click OK.
Note: DTDs may contain specifications for attributes. When you validate a document, InDesign
notifies you about any required attributes that are missing, as well as attribute values that are not
allowed by the DTD.
1 In the Structure pane menu, choose New Comment. Or right-click (Ctrl-click for Mac OS) an
element and select New Comment.
2 In the Value field, type the text you want for the comment. Omit the beginning and ending
indicators (<!-- and -->, respectively). That is, if you type This is a comment the result in the
XML output is:
1 In the Structure pane, click where you want to insert the processing instruction.
2 Click the Structure pane menu, and then choose New Processing Instruction.
3 Enter values in the Target and Data fields. For example, to create the processing instruc-
tion shown in the preceding example, type xml-stylesheet in the Target field and
href="formatting.xsl" type="text/xsl" in the Data field.
4 Click OK. The new processing instruction appears in the Structure pane.
Note: For details about the CALS table specification refer to OASIS (www.oasis-open.org/specs/
tablemodels.php).
<Table>
<Cell>first cell content</Cell>
<Cell>second cell content</Cell>
<Cell>third cell content</Cell>
<Cell>fourth cell content</Cell>
<Cell>fifth cell content</Cell>
<Cell>sixth cell content</Cell>
</Table>
Use attributes to specify the number of columns, cell widths, and other information. When you
export a table from InDesign to XML, some of these formatting attributes are created automati-
cally in the XML file. Because the information is specific to InDesign and provides formatting
information, the table attributes use the aid namespace. The namespace lets you easily identify an
attribute as being part of the table formatting. For details, see “Table attributes” on page 21.
Images
XML generally handles images with a linked reference. When you tag an image frame, InDesign
assigns an href attribute that points to the referenced (linked) image file. The href attribute shows
the file path and filename and appears in the Structure pane as follows:
The href attribute indicates the file path and file name.
InDesign can then export these href attributes in an XML file (as shown below), and can also
process them correctly on import.
<Image href="file://path/images/testfile.jpg"></Image>
To ensure that InDesign exports images correctly, the images must be linked, not embedded.
They must also be properly tagged. Only tagged content is exported, while content that is not
tagged is ignored on export.
Note: The recommended workflow is to work with linked, not embedded, graphics, so that InDesign
can better handle collecting the images in a subfolder during export.
1 Choose Window > Links to open the Links panel and verify that all of your graphics are
up‑to‑date.
2 Use the Tags panel to assign an XML tag, such as Image, to each image. If the tag is not
available in your Tags panel, create it.
When you export images to XML, the images are automatically collected in a subfolder to make
it easier to move the XML file and its linked graphics. The file references in the exported XML
file are then updated to point to the images in the subfolder. On export, you control the final file
format of the images and whether certain images are exported.
2 Specify a file name for the exported file and choose XML as the format.
3 Click Save.
Control the format of your exported images, and whether InDesign includes the original image as well.
5 Set the image options. For detailed instructions, see InDesign Help.
6 Click Export.
Text entities refer to text defined in the XML file or in the DTD. For example, an XML file might
contain a reference to a shared copyright statement:
<WhitePaper>
<!ENTITY copyright "Copyright (c) 2008 Adobe Systems Incorporated The entity definition is in the <!ENTITY ...> section
All Rights Reserved." >
white paper content...
©right; The entity reference starts with an ampersand (&).
</WhitePaper>
When you import XML, text entities are expanded. You do not see the ©right; placeholder
in your InDesign document. Instead, you see the copyright entity text.
XML files can also contain entity references that point to other files. Entity references look
similar to the copyright example above, but the entity definition specifies a file instead of text.
These entities are also expanded on import. InDesign does not preserve the link to the original
entity file.
Note: Unparsed entity references are not processed by InDesign. For images, use an href attribute
that contains the file name instead. If necessary, transform the XML file with XSLT to create the
required structure.
I nDesign provides several different ways of working with XML content. The best approach de-
pends on your workflow:
• For a one-time project, create a blank InDesign document, import the XML file, and then
format the content as needed. This approach is suited for small, unique projects.
Adobe InDesign CS3 and XML: A Technical Reference 10
• To lay out the same type of XML content repeatedly, import the XML file into an InDesign
document that contains paragraph, character, and table styles. Then, associate the XML
tags with the styles in the InDesign document. This approach is faster than applying styles
manually, but requires more planning. If you have several documents that require the same
layout, this workflow will save you time.
• If the XML content contains repeating elements that need to be formatted identically, format
a sample element set and then clone that formatting for the remainder of the XML file.
This approach is very efficient for highly structured content, such as directories or variable data
publishing.
• Instead of associating XML tags with styles using the InDesign mapping feature, embed style
names directly into the XML file using attributes. When you import the XML file into an
InDesign layout that includes those defined styles, InDesign associates the XML tags with
the specified styles automatically. If you control the content of the XML file, this approach
provides additional automation.
• On import, attach an XSL transformation file to the XML file. This new feature in InDe- Extensible Stylesheet Language (XSL) is a powerful
sign CS3 allows you to filter, rearrange, and reorganize the XML structure as you bring it into transformation language designed for processing
XML files. You can find more information about trans-
InDesign.
forming XML with XSL at www.adobe.com/products/
• For complex layout requirements, use the new XML rules feature to assign XML formatting indesign/scripting.
using scripts written in JavaScript, VBScript, or AppleScript. For details, see “XML rules” on
page 25.
You can exclude certain elements by name, which allows you to filter XML information and
display only what you need in the InDesign file. You have the option of linking or embedding the
XML content.
3 If necessary, select Show XML Import Options, and then click Open.
• Create link. Sets up a pointer to the source XML file, which is useful if the XML
file is updated regularly and you want to ensure that your InDesign file remains
up‑to‑date.
Links to an XML file behave like other text and graphics links—if the linked file is
updated outside of InDesign,
InDesign refreshes it. There is, however, one compli-
cation: Because you control how information is displayed by associating the XML
tags with InDesign formatting, changing the structure of the XML file may have
unexpected results. For example, if a new XML tag appears in the linked file, you
may need to modify the InDesign file to accommodate that tag.
• Apply XSLT. Lets you assign a Extensible Stylesheet Language Transformation file
to the XML content, either by browsing for a file or by using the stylesheet file refer-
enced in the XML file as a processing instruction (see page 8 for an example). XSLT
stylesheets let you filter, rearrange, and perform other transformations on the XML
content. For details about XSLT, refer to the World Wide Web Consortium, which
manages the XSL and XSLT specifications (www.w3.org/Style/XSL/).
• Clone repeating text elements. Select this option to replicate the formatting in the
current file for several elements.
InDesign lets you clone a layout for repeating text elements. You can create a single
formatting instance (in this example, for a recipe), and then reuse that layout to
create pages for all of the other content.
Automatically generate repetitive layouts and populate it with your content using the efficient cloning import option. Adobe InDesign CS3 and XML: A Technical Reference 12
• Only import elements that match existing structure. If the XML file contains elements
that you do not want to show in your layout, and your tagged InDesign file does not
use elements of the same name, select this option. Any elements that do not match
a tag used in the InDesign document will not be imported into InDesign.
The XML source file contains several items that are not needed in the InDesign document (as indicated by the
red arrows calling out lines in the XML source above).
The additional items appear in the InDesign document. Items that do not match InDesign structure are removed.
The “Ingredient” and “Instructions” labels are embedded in the template file. In the Story Editor, you can see
that the labels are positioned outside the tags that have content.
• Delete elements, frames, and content that do not match imported XML. If your XML
has elements that occur in only some parts of the content, and are shown in the lay-
out, select this option. On import, if there is an InDesign element or frame associ-
ated with an element that does not appear in the incoming XML file, the InDesign
items will be deleted.
• Import CALS table as InDesign tables. Tables in the XML source file that follow the
CALS specification are converted to InDesign tables during import.
When the XML file is imported, InDesign displays it in the Structure pane. Depending on
whether your layout includes tagged frames that match the imported XML, the content may also
appear automatically in the layout.
Imported XML content appears in the layout window only if you’ve set up tagged frames that match the
XML structure.
Manual formatting is most useful if you rarely receive XML content, or if the structure of the
XML files is unpredictable. It requires very little setup or planning, and you can format the
content at the paragraph or character level. If you link to the XML file, you can preserve any
formatting you’ve applied if you need to update the linked content.
1 In the Structure pane, locate the element you want to lay out.
2 Drag and drop the element to a frame inside your document. If you drop the content on a
blank page, a default text frame is created for it.
Content that is visible on the page has a special icon in the Structure pane. Note that placed content shown here
uses a different icon than unplaced content (shown in the previous image).
The selected element and all of its descendant elements are displayed in the text frame. You
can now apply text formatting to the XML content using the Character, Paragraph, or Control
panels, just as you would to any other text in InDesign. For information about applying text
formatting, see InDesign Help.
1 Import the XML file and lay out the elements you want in your document.
3 You can map tags in three different ways: Note: Mapping tags to style names, and vice-
versa, is exacting. For example, the process
• If the XML tag names match the InDesign style names, click Map by Name.
is case sensitive, so a tag called Body (with a
• If you have an existing InDesign document with the desired style mappings set up, capital B) will not automatically map to a style
click Load and select that file. called body (with a lowercase b).
• If you need to map tags individually, click the corresponding style field (the default
value is Not Mapped) and then choose a style from the pop-up list.
4 Click OK. The mappings you specify are applied to your document.
2 If the Find Format/Change Format options are not shown, click More Options to expand the
dialog box.
3 Specify what you want to find. You can search for text, paragraph styles, characters styles, and
much more. The GREP tab lets you search for a text pattern using wildcards; for details, refer
to InDesign Help and to www.adobe.com/go/learn_id_grep.
4 The Find Format and Change Format fields let you specify that you want to match on styles,
XML tags, or specific formatting. (For example, you can search for text that uses a specific
font and font size.) To assign an XML tag to the found content, click the Specify attributes to
change icon ( ) next to the Change Format field.
You can change the selected text to the specified XML tag.
5 Choose XML in the list of style choices, and then choose an XML tag from the Tag drop-down
list. (If you do not see the tag you want, use the Tags panel to create the tag. You cannot type in
an arbitrary tag name in the Change Format dialog box.)
6 Click OK.
S pecial-purpose attributes in InDesign use either the aid: or aid5: prefix. These prefixes indicate
a namespace.
To use paragraph or character styles, your XML file must declare the aid namespace. To use table
or cell styles, the file must declare the aid5 namespace. The following excerpt shows a file that
declares both namespaces:
Inside the XML file, you must reference the style you want to use with an attribute:
...
<Recipe _ Title aid:pstyle="title">Country Captain's Chicken The aid:pstyle attribute indicates that the
</Recipe _ Title> Recipe_Title element uses the title paragraph style.
<Ingredients aid:pstyle="ingredients">1 sOven Bag, large size (14” x 20”)
2 tbsp. Flour
2 can Stewed tomatoes
1/4 cup Raisins, <Emphasis aid:cstyle="italics">if desired</Emphasis> For character styles, use the aid:cstyle attribute.
When you import this content, InDesign applies the specified paragraph and character styles.
You can define the style’s attributes either before or after importing the XML content. If your
document does not contain the specified styles, InDesign creates and applies default styles
using your specified style names when you import the XML, and you can then edit those
styles afterwards.
<topic>
<title aid:pstyle="h1">Topic title</title>
<para>This first-level topic uses an h1 paragraph style for the title.</para>
...
<topic>
<title aid:pstyle="h2">Subtopic title</title>
<para>This second-level, nested topic uses an h2 paragraph style for the
title.</para>
...
</topic>
</topic>
<Table xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/"
aid5:tablestyle="MyTableStyle">
<Cell aid5:cellstyle="MyCellStyle">A</Cell>
<Cell>B</Cell>
<Cell>C</Cell>
<Cell>D</Cell>
</Table>
Table attributes
The aid and aid5 namespace attributes for tables are described in the following table:
AT T R I B U T E VA LU E D escriptio n
aid:table table Specifies a table-type element. A value of “table” indicates
the container table element; a value of “cell” indicates a cell
cell
element.
aid:trows Numeric Specifies the number of rows in the table. Used only in the
Table element.
aid:tcols Numeric Specifies the number of columns in the table. Used only in
the Table element.
aid5:tablestyle Text Specifies the table’s style. Equivalent to the pstyle attribute
for paragraphs.
aid:theader Empty If present, the theader attribute indicates that the current
cell is part of a table header row.
aid:crows Numeric Specifies how many rows the current cell spans. The
default is 1.
aid:ccols Numeric Specifies how many columns the current cell spans. The
default is 1.
aid:ccolwidth Numeric Specifies the width, in points, of the current cell.
aid5:cellstyle Text Specifies the style of the current cell. Similar to the cstyle
attribute for character styles.
aid:tfooter Empty If present, the tfooter attribute indicates that the current
cell is part of a table footer row.
Sample table. The XML code for the table is shown below.
Notes: The code example that follows uses line breaks and whitespace to improve readability.
Important sample code is shown in bold. In your text editor, the XML may look different.
The pstyle, cstyle, tablestyle, and cellstyle attributes are not shown here. They are not included
when you export XML from InDesign; they are available only to support automatic formatting
when you import XML content into InDesign.
The aid:trows and aid:tcols attributes specify the num-
<Table xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" aid:table="table" ber of rows and columns in the table.
aid:trows="6" aid:tcols="4">
The empty aid:theader attribute indicates a heading
<Cell aid:table="cell" aid:theader="" aid:crows="1" aid:ccols="1"
cell. Footing cells use a similar aid:tfooter attribute.
aid:ccolwidth="130">Table header 1</Cell>
Regular table cells do not have an attribute to indicate
<Cell aid:table="cell" aid:theader="" aid:crows="1" aid:ccols="1" what type they are.
aid:ccolwidth="59">Table header 2</Cell>
<Cell aid:table="cell" aid:theader="" aid:crows="1" aid:ccols="1"
aid:ccolwidth="130">Table header 3</Cell>
<Cell aid:table="cell" aid:theader="" aid:crows="1" aid:ccols="1"
aid:ccolwidth="130">Table header 4</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="2">E straddles two The aid:ccols attribute indicates that the current cell
columns</Cell> spans the specified number of columns. The default,
<Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="130">F 1, indicates no column spanning. The aid:crows
attribute indicates row spanning.
</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="130">G
</Cell>
If you are importing XML tables and want InDesign to format your table automatically, you need
to create XML content that contains the aid and aid5 namespace attributes or that uses the CALS
model.
Note: If your XML content uses a table model other than the two supported by InDesign, consider
using Extensible Stylesheet Language (XSL) transformations to modify the content before or during
import. For details about XSL, see www.w3.org/Style/XSL/
<MonoRuby>
<aid:ruby xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">
<aid:rb>諸行無常</aid:rb>
<aid:rt>しょぎょうむじょう</aid:rt>
</aid:ruby>
To automate the flexible creation of repeating XML elements within InDesign, you need to use
anchored objects in your XML workflow. Anchored objects are items, such as graphic images or
text boxes, that are attached—or anchored—to specific text. The anchored object travels with the
text containing the anchor as the text reflows. (Another alternative is to use XML rules to create
the effect you want. See page 25 for more details.)
Here are a few tips to keep in mind in setting up anchored objects for repeating XML elements:
• You can use anchored objects to handle both text and graphics content that is repeated.
• To automate this workflow, you must set up one story with anchored objects and then clone
the results as you import the full XML data. You do this by creating a frame, pasting it into the
content flow, and then adjusting the position of the newly created anchored object to suit your
layout. (See InDesign Help for tips on positioning anchored objects.) Then, when you import
the XML file, choose Clone Repeating Text Elements.
• When you set up an anchored object be careful about where you position the anchored object
relative to the XML tags to produce the layout you want. For example, the following example
shows the anchored object correctly positioned between the Ingredients end tag and the open-
ing tag for Instructions.
1 Choose View > Structure > Show Tag Markers and View > Structure > Show Tagged Frames to
make the frames easier to see.
3 Create the initial layout by dragging and dropping XML elements from the Structure pane
into text and graphics frames on the page (or use tagged frames to automatically flow the
XML content).
4 Create an untagged text or graphics frame using the type, frame, or drawing tools.
5 Drag and drop the appropriate XML element onto your new text or graphics frame.
Note: Make sure your cursor is positioned at a point in the text that maps to the point in the
Structure pane where you would like the XML element to be inserted.
8 In the Structure pane, note that InDesign created an extra element when you pasted the
frame. Delete the original element and keep the newly created element, which is now properly
anchored. To find out which element maps to the newly created element, right-click one of the
elements in the Structure pane and choose Go To Element. InDesign will then select that ele-
ment in the layout. When you have the right one selected, delete it.
9 Choose Object > Anchored Object > Options to specify the positioning for the anchored frame.
10 Save the resulting InDesign document as a template for automating this layout. Then, when
importing XML content into the template, choose Clone Repeating Text Elements in the XML
Import Options dialog box.
XML rules
XML rules are InDesign script components that allow you to apply actions based on the XML
tags in your document. An XML rule has two components:
• An XPath matching expression that determines which XML tags are processed by the rule.
• A function, which is applied to the tags that are selected by the matching expression.
Note: This discussion of XML rules assumes that you have basic familiarity with InDesign script-
ing. For background on scripting, refer to one of the InDesign CS3 Scripting Guides (www.adobe.
com/products/indesign/scripting) for AppleScript, VBScript, or JavaScript. The examples in this
document are written in JavaScript
In addition to the XML rules, a script that executes XML rules has two other pieces:
• XML rules processor (a scripting object) — Locates XML elements in an XML structure using
XPath and applies the appropriate XML rule(s). A script can contain multiple XML rule pro-
cessor objects, and each rule-processor object can be associated with a given XML rule set.
• Glue code — A set of routines provided by Adobe to make the process of writing XML rules
and interacting with the XML rules-processor easier.
The following example shows a simple InDesign script that contains a single XML rule:
function main(){
if (app.documents.length != 0){
var myDocument = app.documents.item(0);
var myRuleSet = new Array (new AddIngredientLabel); The AddIngredientLabel XML rule is declared here.
with(myDocument){
var elements = xmlElements;
_ _ processRuleSet(elements.item(0), myRuleSet); processRuleSet is part of the glue code that Adobe
} provides to help you with XML processing.
To run a script:
1. Select a script in the Script panel (Window > Automation > Scripts).
Exporting XML
You can export XML from any I nDesign file. InDesign exports only the information that is
tagged in the Structure pane. Content in untagged text frames, embedded images, and untagged
images are not exported.
To export XML:
1 Make sure that all of the information you want to export is tagged. (If necessary, use the Tags
panel to assign tags.)
2 (Optional) If you want to export only information below a specific element, select that element
in the Structure pane.
4 Specify a file name and location and select XML as the file type. Click Save.
• To include a reference to your DTD in the XML file, select the corresponding
option.
• To display the XML after it is created, select View XML Using and specify the
editor of your choice.
• To export starting with the element you selected in step 2, select Export From
Selected Element.
• To export untagged tables as CALS tables, select the corresponding option. If you
do not select this option, any untagged tables are discarded on export. Tagged
tables are exported using the InDesign table model.
• To use decimal character entities for breaks, whitespace, and other special char-
acters, select the Remap Break, Whitespace, and Special Characters option. For
details on InDesign’s mapping for special characters, see Appendix B on page 32.
Adobe InDesign CS3 and XML: A Technical Reference 27
• To apply an XSL transformation during export, select the Apply XSLT option and
then specify a stylesheet. You can browse for a file on your system. If the structure
contains a processing instruction with a stylesheet reference, you can use that
stylesheet. See “Inserting processing instructions” on page 8 for an example.
Note: For information about image export options, see “Images” on page 9.
5 Click Export.
XML files use Unicode encoding. If you try to open the XML file in an editor or viewer that does
not support Unicode, you may see error messages or character substitution in your output XML,
so be sure to use a Unicode-compliant editor. If you plan to transform the XML files into HTML
for display on the web, be to use the remapping option for special characters. XML and InDesign
support a wider range of characters than HTML does.
A snippet is an InDesign object or group of objects that have been exported from a document to
share with others or re-use in your workflow. These files might be comprised of text, imported
graphics, native InDesign objects, styled tables—whatever you can lay out on an InDesign page.
You create a snippet by selecting the objects you want to reuse and then dragging and dropping
them onto your desktop, into Adobe Bridge, or into a Library panel, or by choosing File > Export
and choosing InDesign Snippet for Format. When you place or drag a snippet back into a layout,
InDesign recreates the original objects, their formatting, their relative positioning on the page,
and any XML tags that have been applied. (A snippet is an XML wrapper on a series of InDesign
scripting calls that direct InDesign how to reproduce the file.)
You can integrate snippets into an XML workflow to achieve more production efficiency. Here
is an example of how this might work: Imagine that you update and publish tables of data daily
or weekly. For example, you might publish sports scores, top 10 lists, or weather information in
tables. The basic design of those tables doesn’t vary, though you might freshen the color scheme
regularly. One way to streamline this process would be to use snippets.
You simply design and tag the tables, link them to the XML data you publish, and then export
each of them as a snippet. The snippet preserves the XML tags and the linked data. When you
drag and drop one of the snippets into another InDesign layout, you can then tweak the design,
Adobe InDesign CS3 and XML: A Technical Reference 28
update the link to the XML data, and publish the results. The entire process can happen in a few
quick steps.
For more information about working with InDesign snippets, see the InDesign online Help system.
Note: The INX format is not intended to be human readable or to be used as a long-term archiving
format. We do not recommend trying to create or edit INX files using a text editor or storing snippets
in a database.
To start, you may want to experiment with a small amounts of content. You might, for example,
export some articles to XML for reuse on a website or consider whether some database informa-
tion could be linked into your publication automatically.
Once you have configured the basic publishing system, you can use scripting to further auto-
mate and streamline your XML publishing. Virtually everything in InDesign is scriptable. You
can write scripts in JavaScript (for cross-platform compatibility), VBScript, or AppleScript. For
details about scripting, see the InDesign Scripting Guides and sample scripts on your installation
DVD. You can also get more information on the Adobe website at www.adobe.com/products/
indesign/scripting.
• Empty tags must include a closing slash before the end of the tag, as shown in these examples:
<br/>
<img src="file.gif"/>
• Tag names cannot contain spaces or special characters and must start with an alphabetic character.
Note: For a complete discussion of XML syntax, see the XML Recommendation at www.w3.org/
TR/2004/REC-xml-20040204/.
Working with structure rules and valid files gives you the ability to define and enforce document
organization. With a DTD or Schema file, you can set up requirements for your content. Concep-
tually, this process is similar to creating a formatting template, but with structure rules, you can
require that documents must follow the rules you establish. You could, for example, specify that a
story must begin with a title and a byline. For an academic journal, you could require an abstract
at the beginning of an article. You can require that bibliographic information must be organized
a certain way. Structure rules let you ensure that documents are consistent.
I nDesign lets you work with or without a DTD, but you must provide a DTD if you want to
validate your documents.
In XML, the DTD is declared at the top of the file, as shown here:
Instructions
Notes
Number_of_Servings
• NewsML (www.newsml.org)
• SportsML (www.sportsml.org)
• Technical documents:
• DocBook (www.oasis-open.org/committees/tc_home.php?wg_abbrev=docbook)
Adobe, the Adobe logo, Acrobat, and InDesign are either registered
trademarks or trademarks of Adobe Systems Incorporated in the United
States and/or other countries. Microsoft, Windows, and Windows NT are
either registered trademarks or trademarks of Microsoft Corporation in
the United States and/or other countries. W3C is a trademark (registered
in numerous countries) of the World Wide Web Consortium; marks of
W3C are registered and held by its host institutions MIT, ERCIM and
Kelo. All other trademarks are the property of their respective owners.