Exporting XML. Adobe InDesign CS6
Реклама
Реклама
C HAPTER 12: XML Adding XML Elements to a Layout 198 tell application "Adobe InDesign CS6" set myDocument to make document tell myDocument set myXMLTag to make XML tag with properties {name:"myXMLElement"} set myRootXMLElement to XML element 1 end tell tell myRootXMLElement set myXMLElementA to make XML element with properties
{markup tag:myXMLTag, contents:"This is a paragraph in an XML story."} set myXMLElementB to make XML element with properties
{markup tag:myXMLTag, contents:"This is another paragraph in an XML story."} set myXMLElementC to make XML element with properties
{markup tag:myXMLTag, contents:"This is the third paragraph in an example XML story."} set myXMLElementD to make XML element with properties {markup tag:myXMLTag, contents:"This is the last paragraph in the XML story."} end tell set myXMLStory to xml story 1 of myDocument set the point size of text 1 of myXMLStory to 72 end tell
Exporting XML
To export XML from an InDesign document, export either the entire XML structure in the document or one
XML element (including any child XML elements it contains). The following script fragment shows how to do this (for the complete script, see ExportXML): tell myDocument export to "yukino:test.xml" format "XML" end tell
In addition, you can use the export from selected
property of the xml export preferences
object to export an XML element selected in the user interface. The following script fragment shows how to do this
(for the complete script, see ExportSelectedXMLElement): tell myDocument set export from selected of xml export preferences to true select xml element 2 of xml element 1 export to "yukino:selectedXMLElement.xml" format "XML" set export from selected of xml export preferences to false end tell
Adding XML Elements to a Layout
Previously, we covered the process of getting XML data into InDesign documents and working with the
XML structure in a document. In this section, we discuss techniques for getting XML information into a page layout and applying formatting to it.
Associating XML elements with page items and text
To associate a page item or text with an existing XML element, use the place xml
method. This replaces the content of the page item with the content of the XML element, as shown in the following script fragment (from the PlaceXML tutorial script):
C HAPTER 12: XML Adding XML Elements to a Layout 199 tell text frame 1 of page 1 of myDocument place XML using xml element 1 of myDocument end tell
To associate an existing page item or text object with an existing XML element, use the markup method.
This merges the content of the page item or text with the content of the XML element (if any). The following script fragment shows how to use the markup
method (for the complete script, see Markup): tell XML element 1 of XML element 1 of myDocument markup text frame 1 of page 1 of myDocument end tell
Placing XML into page items
Another way to associate an XML element with a page item is to use the place into frame
method. With this method, you can create a frame as you place the XML, as shown in the following script fragment (for the complete script, see PlaceIntoFrame): tell application "Adobe InDesign CS6" set myDocument to document 1 tell view preferences of myDocument set horizontal measurement units to points set vertical measurement units to points end tell
--place into frame has two parameters:
--on: The page, spread, or master spread on which to create the frame
--geometric bounds: The bounds of the new frame (in page coordinates).
tell XML element 1 of myDocument place into frame on page 1 geometric bounds {72, 72, 288, 288} end tell end tell
To associate an XML element with an inline page item (i.e., an anchored object), use the place into copy method, as shown in the following script fragment (from the PlaceIntoCopy tutorial script): tell application "Adobe InDesign CS6" set myDocument to document 1 set myPage to page 1 of myDocument set myTextFrame to text frame 1 of myPage tell XML element 1 of myDocument set myFrame to place into copy on myPage place point {288, 72} copy item myTextFrame end tell end tell
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 place into inline copy method, as shown in the following script fragment (from the PlaceIntoInlineCopy tutorial script):
C HAPTER 12: XML Adding XML Elements to a Layout 200 tell application "Adobe InDesign CS6" set myDocument to document 1 set myPage to page 1 of myDocument tell myPage set myNewTextFrame to make text frame with properties
{geometric bounds:{72, 72, 96, 144}} end tell set myXMLElement to XML element 3 of XML element 1 of myDocument set myFrame to place into inline copy myXMLElement copy item myNewTextFrame without retain existing frame end tell
To associate an XML element with a new inline frame, use the placeIntoInlineFrame method, as shown in the following script fragment (from the PlaceIntoInlineFrame tutorial script): set myDocument to document 1 set myXMLElement to xml element 2 of xml element 1 of myDocument set myFrame to place into inline frame myXMLElement place point {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): tell application "Adobe InDesign CS6" set myDocument to make document tell myDocument set myXMLTag to make XML tag with properties {name:"myXMLElement"} set myRootXMLElement to XML element 1 tell myRootXMLElement set myXMLElementA to make XML element with properties
{markup tag:myXMLTag} set contents of myXMLElementA to "This is a paragraph in an XML story." set myXMLElementB to make XML element with properties
{markup tag:myXMLTag} set contents of myXMLElementB to "This is a another paragraph in an
XML story." set myXMLElementC to make XML element with properties {markup tag:myXMLTag} set contents of myXMLElementC to "This is the third paragraph in an
XML story." set myXMLElementD to make XML element with properties {markup tag:myXMLTag} set contents of myXMLElementD to "This is the last paragraph in an XML story." tell myXMLElementA
--By inserting the return character after the XML element, the
--character becomes part of the content of the parent XML element,
--and not part of the content of the XML element itself.
insert text as content using return position after element end tell tell myXMLElementB insert text as content using "Static text: " position before element insert text as content using return position after element end tell
Завантажити
Реклама