Adobe 0046100128056 Scripting Guide - Page 168
Loading XML tags, Saving XML tags, Creating an XML element, Moving an XML element, Deleting an XML
UPC - 718659087562
View all Adobe 0046100128056 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 168 highlights
CHAPTER 12: XML Scripting XML Elements 168 Loading XML tags You can import XML tags from an XML file without importing the XML contents of the file. You might want to do this to work out a tag-to-style or style-to-tag mapping before you import the XML data., as shown in the following script fragment (from the LoadXMLTags tutorial script): myDocument.loadXMLTags(File("/c/test.xml")); Saving XML tags Just as you can load XML tags from a file, you can save XML tags to a file, as shown in the following script. When you do this, only the tags themselves are saved in the XML file; document data is not included. As you would expect, this process is much faster than exporting XML, and the resulting file is much smaller. The following sample script shows how to save XML tags (for the complete script, see SaveXMLTags): myDocument.saveXMLTags(File("/c/xml_tags.xml"), "Tag set created October 5, 2006"); Creating an XML element Ordinarily, you create XML elements by importing an XML file, but you also can create an XML element using InDesign scripting, as shown in the following script fragment (from the CreateXMLElement tutorial script): var myDocument = myInDesign.documents.add(); var myXMLTagA = myDocument.xmlTags.add("XML_tag_A"); var myXMLElementA = myDocument.xmlElements.item(0).xmlElements.add(myXMLTagA); myXMLElementA.contents = "This is an XML element containing text."; Moving an XML element You can move XML elements within the XML structure using the move method, as shown in the following script fragment (from the MoveXMLElement tutorial script): var myRootXMLElement = myDocument.xmlElements.item(0); var myXMLElementA = myRootXMLElement.xmlElements.item(0); myXMLElementA.move(LocationOptions.after, myRootXMLElement.xmlElements.item(2)); myRootXMLElement.xmlElements.item(-1).move(LocationOptions.atBeginning); Deleting an XML element Deleting an XML element removes it from both the layout and the XML structure, as shown in the following script fragment (from the DeleteXMLElement tutorial script). myRootXMLElement.xmlElements.item(0).remove(); Duplicating an XML element When you duplicate an XML element, the new XML element appears immediately after the original XML element in the XML structure, as shown in the following script fragment (from the DuplicateXMLElement tutorial script):