InDesign ScriptingTutorial
InDesign ScriptingTutorial
Help
ADOBE INDESIGN 2.0 2
Using XML in Adobe InDesign
Element In InDesign, an element is an XML tag that Creating and importing XML tags
appears in the Structure view window when you tag a
Before you tag your document’s content for XML
page item. Child elements are subordinate to parent
export, you need a list of tags in the Tags palette to work
elements in the structure. Sibling elements appear on the
with. You can create XML tags from scratch, or you
same hierarchical level.
can import them from another source. In most XML
Attribute A string that describes an element using tags workflows, a team member determines the set of tags
or syntax understood in the XML language. Attributes you’ll use—make sure you and your team members use
contain a name and a value that can provide information tags consistently.
about the element’s content, such as when it was created
and by whom.
Page items Frames, graphics, tables, and text in an
InDesign document.
Help
ADOBE INDESIGN 2.0 3
Using XML in Adobe InDesign
2 Choose New Tag from the Tags palette menu, or click After you tag items, the elements appear in the
the New Tag button at the bottom of the Tags palette. Structure view window, which represents the structured
3 Type a name for the tag. InDesign checks to make content in the document. If you tag a section of text
sure that you include valid XML tag names according to within a frame, the new element appears in Structure
XML standards. If you include a space or an illegal view as a child element of the parent frame.
character in the tag name, an alert message appears
when you click OK.
4 Specify a color for the tag. You can use the same color
for multiple tags. The color you select appears when you
apply the tag to a frame and choose View > Show
Tagged Frames, or when you apply the tag to text within
a frame and choose View > Show Tag Markers. Tag
colors do not appear in the exported XML file.
5 Click OK.
To edit a tag:
You can tag page items such as text frames and graphics • Using a selection tool, select a text frame or a graphics
frames, including nested frames. You can also tag blocks frame, drag the frame to the Structure view window,
of text within a text frame to add a level of detail to the and select a tag name from the menu that appears.
XML file. For example, you may want to apply an
<Article> tag to a text frame, and then apply specific
text tags, such as <Title> and <Body>, to paragraphs
within the text frame. (When you tag a frame in a
threaded story, all other frames in the story are tagged.)
Help
ADOBE INDESIGN 2.0 4
Using XML in Adobe InDesign
1 Make sure that the text frame in which the text Choose View > Show Tagged Frames or Hide Tagged
appears is tagged. (If the frame isn’t tagged when you try Frames.
to tag selected text within the frame, you are prompted
to select a tag for the frame.)
2 Do one of the following:
• Using the type tool, select text within a text frame,
and then click a tag in the Tags palette. (If you select
all the text within the frame, the tag is applied to the
frame, not to the block of text.)
• Automatically tag paragraphs to which paragraph
styles have been applied using the Map Styles to Tags
command; see “Mapping styles and tags for XML” on
page 10.
In this example, all page items are tagged except for the subhead
To retag page items: below “Wonderfully Different.”
Help
ADOBE INDESIGN 2.0 5
Using XML in Adobe InDesign
• When you tag selected text, a child element appears in To delete an element:
the Structure view window under the text frame tag. Select the element in the Structure view window, and
When you tag a text frame or graphics frame, an then choose Delete Element from the Structure pop-up
element is added to the appropriate location in menu in Structure view.
Structure view.
• You can tag a master page item, but only one instance To untag page items:
of the corresponding element appears in Structure 1 Select the element in the Structure view window, or
view, regardless of how many times the item appears select the page item in the document layout.
on document pages. You can manually override and
2 Click Untag in the Tags palette.
tag master page items that appear on document
pages. Overridden master page items appear as
separate elements in Structure view.
Structuring documents for XML
The Structure view window displays a hierarchical tree
Deleting tags and elements
of tagged page items and imported XML content. Items
You can delete tags in the Tags palette, and you can that appear in the Structure tree are called elements.
delete elements in Structure view. When you delete a tag Structure view shows at a glance what elements have
that has been applied to content, you can specify a been placed on the page and what have not (a blue
different tag that will be applied to the same content diamond on an element icon indicates that the element
instead of the deleted tag. You can also select and delete is attached to a page item). You select and move
all unused tags. elements in Structure view to define the sequence and
When you delete an element in Structure view, both the hierarchy of page items in the exported XML file.
element and the layout content are deleted, but the
frame of the deleted element remains in the layout. If
the deleted element is a parent element, the child
elements are deleted too.
A
B
If you want to delete an element without deleting the
content, click Untag in the Tags palette to untag the
page item.
C
D
To delete tags:
Help
ADOBE INDESIGN 2.0 6
Using XML in Adobe InDesign
Do one of the following: Click the triangle next to the element you want to
expand or collapse. Hold down Ctrl (Windows) or
• Position the mouse pointer over the right edge of the
Command (Mac OS) while clicking the triangle to
Structure view window so that the pointer becomes a
expand or collapse all elements contained within the
double-sided arrow , and then drag left or right to
current element.
resize the Structure view window.
• Drag the splitter button splitter button left or To show or hide text snippets:
right to resize the Structure view window.
Choose Structure > Show Text Snippets or Hide Text
Snippets. Showing or hiding text snippets sets the
Using the Structure view window default for any new document you create.
When a tagged page item is selected in the document
layout, the corresponding item appears in bold in Rearranging elements in Structure view
Structure view. The following icons appear in
You can rearrange the XML structure by dragging
Structure view:
elements to different positions in Structure view.
Icon Name Use Changing the hierarchy affects the structure of exported
XML files, but it doesn’t affect the position of frames in
Root element Each document includes one root
document, which can be renamed, your layout. However, if you rearrange the order of
but it cannot be moved, deleted, or child elements within a text frame in Structure view, the
associated with page item. corresponding text in the document layout is also
Story element Represents tagged stories (one or rearranged. You cannot move the Root element.
more linked frames).
To rearrange the order of elements in Structure view:
Text element Represents XML-tagged text within
a frame Click the element to select it, and then drag it to a new
Graphic Represents a tagged frame that location within the structure tree. If you want to make
element includes a placed image. Each graphic an element a child element, select it and drag it to so
element includes an “href” attribute that the parent element is highlighted, and then release
that defines the path or URL to the
linked file. the mouse button.
Any element in Structure view can have attributes— To copy and paste elements:
optional pieces of information about that element, such 1 In the Structure view window, select the element or
as the revision date of an article. Attributes appear only elements you want to copy, and then choose Edit >
in Structure view. Copy.
Story elements include a text snippet (the first 32 2 Select the element where you want the element to
characters of the story) next to the element. You can appear, and then choose Edit > Paste.
hide snippets in Structure view. Table elements do not
display snippets.
Help
ADOBE INDESIGN 2.0 7
Using XML in Adobe InDesign
1 Select the element below which you want the element To edit an attribute:
to appear.
1 Double-click an attribute, or select an attribute and
2 Select New Element from the Structure pop-up choose Edit Attribute from the Structure menu in
menu in Structure view, or click . Structure view.
3 Select the tag to be used for the element, and then 2 Edit the attribute as needed, and then click OK.
click OK.
4 Move the new element within the structure as To delete an attribute:
necessary. Drag tagged elements to the new element to Select an attribute, and then choose Delete Attribute
add them as children. from the Structure pop-up menu in Structure view.
An attribute describes an element using tags or syntax Choose Show Attributes or Hide Attributes from the
understood in the XML language. An attribute consists Structure pop-up menu in Structure view.
of a name (such as href or keywords) and a value. When
you tag a placed graphic, an href attribute appears
automatically; it specifies the location of the graphic Exporting a document to XML
file. You can edit this href attribute; see “About After you tag the document’s page items, you’re ready to
importing and exporting graphics for XML” on page 9. export a document to XML. You can export the entire
You can also add optional attributes to any element. For set of tagged page items, or you can export only a
example, to include keywords for searching in another specified portion. Once the document is exported, you
downstream application, you can create an attribute can make additional changes to the XML file using a
called keywords. You can also create attributes to program such as Adobe GoLive®, or you can import the
indicate substituted text, article titles, and other XML XML file into an InDesign 2.0 document or another
content-related information. downstream application.
1 Do the following:
• To prepare for export, make sure that tags have been
applied to the necessary page items; see “Tagging
page items for XML” on page 3.
• If you want to export only a portion of the document,
select the element in Structure view where you want
exporting to begin.
2 Choose File > Export.
An attribute includes a name and a value
Help
ADOBE INDESIGN 2.0 8
Using XML in Adobe InDesign
3 Choose XML for Save as Type (Windows) or Formats You can also flow contents into an InDesign document
(Mac OS). that acts as a template. The template document contains
4 Type the name and specify the location of the XML tagged page items. If you set up your template
file, and then click Save. The Export XML Options document properly, the contents of the XML file will
dialog box appears. flow into the tagged page items of the template
document. See “Setting up a document for importing
5 For Comments, type text that will appear in a XML tags” on page 9.
comment field near the top of the exported XML file.
6 To view the exported XML file, select the View XML
Using option, and specify the browser or XML editing
application in which the exported XML file will appear.
7 If you selected an element in Structure view, you can
select Export from Selected Element to export only the
selected portion of the document. If no element is
selected, this option is dimmed.
8 For Encoding, select UTF8, UTF16, or Shift-JIS (for Before and after importing an XML file into an
Japanese characters). Note that some applications such InDesign document
as Adobe GoLive do not support UTF16.
To import an XML file and its contents into a blank
9 Click OK to export the XML file.
document:
When you import an XML file into an InDesign To import an XML file and its contents into a template
document, you specify whether imported elements document:
replace existing content or are appended to the
1 Open the document in which the XML content will
contents. Imported XML files contain no text
appear.
formatting information, because XML separates form
and content. 2 Do any of the following:
You can flow XML text into any document. If you flow • Create a template document for importing XML tags;
text into a blank document, untagged elements appear see “Setting up a document for importing XML tags”
in the Structure view window. You can then drag on page 9.
elements from Structure view to the document layout. • If the document already contains XML elements, you
When you drag and drop elements, the content uses the may want to select an element in Structure view into
document’s default text and graphics characteristics. which the imported structure will flow.
You can then reformat this content by mapping tags to
3 Choose File > Import XML.
styles; see “Mapping tags to styles” on page 10.
4 Select the XML file you want to import.
Help
ADOBE INDESIGN 2.0 9
Using XML in Adobe InDesign
5 Do one of the following: • Make sure the tagged page items appear in the same
• Select Replace Content to replace existing tagged order as they appear in the XML file. Compare the
page items; see “Setting up a document for importing order of the tags in the XML file with the order of the
XML tags” on page 9. elements in the document’s Structure view. If the
order is different, rearrange the elements in Structure
• Select Append Content to create new elements at the view so that they coincide with the order of the XML
end of the structure. file’s tag order.
6 Select Import into Selected Element to import XML • If you want text to retain its formatting during XML
content into the element selected in Structure view. If import, apply paragraph styles to the tagged place-
this option is not selected, imported elements will holder text within a frame, or to the text frame itself.
appear under the root element. The imported XML text will retain the style’s
7 Click Open. formatting, but the style will no longer be applied to
the imported text.
Setting up a document for importing XML tags • If individual paragraphs are tagged in the imported
When you select Replace Content in the Import XML XML file, you may want to tag paragraphs within text
dialog box, the content flows into the elements with frames using the same tags and using the same order.
matching tags. Replacement starts where the root of the • Make sure tables include the same number of rows
XML file matches the tag of the selected element. and columns as the tables in the imported XML file.
Imported table data will replace the contents of the
The key is to be rigorous about setting up your tagging
placeholder table, but the table’s structural
structure, so that tag names and values are used consis-
formatting will remain intact.
tently in your XML files and your InDesign templates.
When you set up the document into which the XML file • You can import XML content into placeholders on
is imported, be aware that the order in which elements master pages. However, automatic page number
are inserted into a document is determined by the order characters used in headers and footers are not
of the XML file, not by the InDesign file. For example, preserved.
if you have an InDesign document with elements in
Tag2, Tag1 order and the XML file lists these elements in
Tag1, Tag2 order, only Tag1 will appear in the InDesign About importing and exporting
document; Tag2 will appear in the Structure view graphics for XML
window, but will not be flowed into the document.
When you tag a placed image, InDesign automatically
If you want XML elements to replace existing content, creates an attribute called “href ” that defines the
you can create a template that includes placeholder text location of the image file. You can edit this attribute to
with appropriate styles. specify a new location of the image. For example, your
image files may be on your hard drive, but when you
When creating a template, do the following:
transfer the XML and associated image files, these href
• Create text and graphics placeholders in an InDesign attributes will no longer be valid on someone else’s
document, and then tag them using the same tag computer. You can edit the attribute to add relative
names used in the XML file. paths so that others will have access to these files.
To make sure you’re using the same tag names, you By the default, an href attribute may look like the
may want to load the tags from the XML file; see following:
“Creating and importing XML tags” on page 2.
href=file://C:/Photos/Meadow.psd
If the image files will appear in the same folder as the
exported XML file, edit the attribute as follows:
href=file:Meadow.psd
Help
ADOBE INDESIGN 2.0 10
Using XML in Adobe InDesign
If the image files will appear in a subfolder in the folder To map styles to tags for export:
in which the XML file is located, edit the attribute 1 Set up the necessary styles in your document.
as follows:
2 Choose Map Styles to Tags from the Tags palette
href=file://Photos/Meadow.psd menu.
3 To match style names to tag names, click Map by
To edit an href attribute:
Name. Styles that are named identically to tag names
1 In the Structure view window, double-click the are selected in the dialog box, not created. Map by
attribute (you may need to click the triangle icon next Name is case-sensitive, so H1 and h1 would be treated
to the image element to display the attribute. as different tags.
2 For Value, type the new path of the image, and then 4 For each style in the current document, specify the
click OK. tag that you want it to be mapped to.
5 To import styles from another document, choose
Load, specify the file, and then click OK.
Mapping styles and tags for XML
6 Click OK.
You can save time by mapping styles to tags before you
export to XML, or by mapping tags to styles after you
import an XML file. You can edit the mappings at any Mapping tags to styles
time. When you map tags to styles, you make sure that tagged
paragraphs are also formatted with paragraph styles.
You can apply the same style to different tags. For
example, you can map Head1 and Head 2 paragraph
styles to the H1 tag.
Help
ADOBE INDESIGN 2.0 11
Using XML in Adobe InDesign
About using Acrobat structure tags To add PDF structure tags to the Tags palette:
for PDF export 1 Choose View > Show Structure to display the
Structure view window.
Adobe Acrobat includes a set of structure tags, such as
Article, Figure, and Artifact, for creating structured 2 Choose Add Untagged Items from the Structure pop-
PDF files. If you select Include eBooks Tags when you up menu in Structure view.
export a document to PDF, these tags are applied to the
document automatically. However, you can use Applying Acrobat tags to the InDesign
Structure view to add additional Acrobat tags or to fine- document
tune existing tags.
Note the following suggested uses for each imported tag:
By applying Acrobat tags to your document, you can
Story Use this tag for text frames. The Story tag is
create a re-flowable PDF file for viewing on handheld
applied to all untagged text frames when you choose
devices and other media. For example, if you tag a page
Add Untagged Items.
item as Artifact, the page item will not be displayed in
Reflow view on some handheld devices. Figure Use this tag for placed graphics. The Figure tag
is applied to all untagged graphics placed in your
document when you choose Add Untagged Items.
Adding structure tags to the Tags palette
Artifact The Artifact tag lets you hide page items when
When you choose the Add Untagged Items command,
InDesign adds Acrobat structure tags to the Tags viewing the exported PDF file in Reflow view. This is
palette, and applies the Story and Figure tags to certain especially useful for viewing PDF files on handheld
untagged page items. The Story tag is applied to any device or in other PDF readers.
untagged text frames, and the Figure tag is applied to Paragraph tags (P, H, H1–H6) These tags have no effect
any untagged graphics. You can then manually apply on the exported PDF text when viewed in Reflow view.
other tags to sections of text. However, tagging page However, they can be useful in some situations when
items does not guarantee that the items will be struc- exporting a PDF file to HTML format.
tured accordingly in the exported PDF file. For more
information, see “Applying Acrobat tags to the
InDesign document” on page 11.
Adobe, the Adobe logo, and InDesign are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or
other countries. Windows is either a registered trademark or trademark of Microsoft Corporation in the United States and/or other countries.
Macintosh is a trademark of Apple Computer, Inc., registered in the United States and other countries. Flash is a trademark of Macromedia, Inc.
©2001 Adobe Systems Incorporated. All rights reserved.