Creating An Xml Element; Moving An Xml Element; Deleting An Xml Element; Duplicating An Xml Element - Adobe 65009333 - InCopy CS4 - PC Manual

Scripting guide: javascript
Hide thumbs Also See for 65009333 - InCopy CS4 - PC:
Table of Contents

Advertisement

XML
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 InCopy scripting, as shown in the following script fragment (from the CreateXMLElement tutorial
script):
var myXMLTag = myDocument.xmlTags.add("myXMLTag");
var myRootElement = myDocument.xmlElements.item(0);
var myXMLElment = myRootElement.xmlElements.add(myXMLTag);
myXMLElement.contnets = "This is an XML element containing text."

Moving an XML element

You can move XML elements within the XML structure using the
script fragment (from the MoveXMLElement tutorial script):
var myDocument = app.documents.add();
var myRootXMLElement = myDocument.xmlElements.item(0);
var myXMLTag = myDocument.xmlTags.add("xml_element");
var myXMLElementA = myRootXMLElement.xmlElements.add(myXMLTag);
myXMLElementA.contents = "A";
var myXMLElementB = myRootXMLElement.xmlElements.add(myXMLTag);
myXMLElementB.contents = "B";
var myXMLElementC = myRootXMLElement.xmlElements.add(myXMLTag);
myXMLElementC.contents = "C";
var myXMLElementD = myRootXMLElement.xmlElements.add(myXMLTag);
myXMLElementD.contents = "D";
//Move the XML element containing "A" to after
//the XML element containing "C"
myXMLElementA.move(LocationOptions.after, myRootXMLElement.xmlElements.item(2));
//Move the XML element containing "D" to the beginning of its parent.
myRootXMLElement.xmlElements.item(-1).move(LocationOptions.atBeginning);
//Place the XML structure so that you can see the result.
myDocument.stories.item(0).placeXML(myRootXMLElement);

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):
Scripting XML Elements 80
method, as shown in the following
move

Advertisement

Table of Contents
loading

This manual is also suitable for:

Incopy cs4

Table of Contents