Adobe 65009333 Scripting Guide - Page 80

Creating an XML element, script fragment from the MoveXMLElement tutorial script

Page 80 highlights

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

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88

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