Marking Up Existing Layouts - Adobe 0046100128056 - InDesign - Mac Manual

Javascript
Table of Contents

Advertisement

C
12: XML
Adding XML Elements to a Layout 172
HAPTER
var myPage = myDocument.pages.item(0);
var myXMLElement = myDocument.xmlElements.item(0);
myXMLElement.placeIntoCopy(myPage, [288, 72], myPage.textFrames.item(0), true);
To associate an existing page item (or a copy of an existing page item) with an XML element and insert the
page item into the XML structure at the location of the element, use the
method,
placeIntoInlineCopy
as shown in the following script fragment (from the PlaceIntoInlineCopy tutorial script):
var myPage = myDocument.pages.item(0);
var myTextFrame = myDocument.textFrames.add({geometricBounds:[72, 72, 96, 144]});
var myXMLElement = myDocument.xmlElements.item(0).xmlElements.item(2);
myXMLElement.placeIntoInlineCopy(myTextFrame, false);
To associate an XML element with a new inline frame, use the
method, as shown
placeIntoInlineFrame
in the following script fragment (from the PlaceIntoInlineFrame tutorial script):
var myXMLElement = myDocument.xmlElements.item(0).xmlElements.item(2);
//Specify width and height as you create the inline frame.
myXMLElement.placeIntoInlineFrame([72, 24]);
Inserting text in and around XML text elements
When you place XML data into an InDesign layout, you often need to add white space (for example, return
and tab characters) and static text (labels like "name" or "address") to the text of your XML elements. The
following sample script shows how to add text in and around XML elements (for the complete script, see
InsertTextAsContent):
var myXMLElement = myDocument.xmlElements.item(0).xmlElements.item(0);
//By inserting the return character after the XML element, the character
//becomes part of the content of the parent XML element, not of the element itself.
myXMLElement.insertTextAsContent("\r", LocationOptions.after);
myXMLElement = myDocument.xmlElements.item(0).xmlElements.item(1);
myXMLElement.insertTextAsContent("Static text: ", LocationOptions.before);
myXMLElement.insertTextAsContent("\r", LocationOptions.after);
//To add text inside the element, set the location option to beginning or end.
myXMLElement = myDocument.xmlElements.item(0).xmlElements.item(2);
myXMLElement.insertTextAsContent("Text at the start of the element: ",
LocationOptions.atBeginning);
myXMLElement.insertTextAsContent(" Text at the end of the element.",
LocationOptions.atEnd);
myXMLElement.insertTextAsContent("\r", LocationOptions.after);
//Add static text outside the element.
myXMLElement = myDocument.xmlElements.item(0).xmlElements.item(3);
myXMLElement.insertTextAsContent("Text before the element: ", LocationOptions.before);
myXMLElement.insertTextAsContent(" Text after the element.", LocationOptions.after);
//To insert text inside the text of an element, work with the text objects contained by
the element.
myXMLElement.words.item(2).insertionPoints.item(0).contents = "(the third word of) ";

Marking up existing layouts

In some cases, an XML publishing project does not start with an XML file—especially when you need to
convert an existing page layout to XML. For this type of project, you can mark up existing page-layout
content and add it to an XML structure. You can then export this structure for further processing by XML
tools outside InDesign.

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs5

Table of Contents