XML Scripting XML Elements 100
Rem You can create an XML tag without specifying a color for the tag.
Set myXMLTagA = myDocument.XMLTags.Add("XML_tag_A")
Rem You can define the highlight color of the XML tag using the UIColors enumeration...
Set myXMLTagB = myDocument.XMLTags.Add("XML_tag_B", UIColors.Gray)
Rem ...or you can provide an RGB array to set the color of the tag.
Set myXMLTagC = myDocument.XMLTags.Add("XML_tag_C", Array(0, 92, 128))
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 importing the XML data, as shown in the following script fragment (from the LoadXMLTags tutorial script): myDocument.LoadTags("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("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):
Set myXMLTag = myDocument.XMLTags.Add("myXMLTag")
Set myRootElement = myDocument.XMLElements.Item(1)
Set myXMLElement = myRootElement.XMLElements.Add(myXMLTag) myXMLElement.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):
Set myDocument = myInCopy.Documents.Add
Set myXMLTag = myDocument.XMLTags.Add("myXMLTag")
Set myRootElement = myDocument.XMLElements.Item(1)
Set myXMLElementA = myRootElement.XMLElements.Add(myXMLTag) myXMLElementA.Contents = "This is XML element A."
Set myXMLElementB = myRootElement.XMLElements.Add(myXMLTag) myXMLElementB.Contents = "This is XML element B." myXMLElementA.Move idLocationOptions.idAfter, myXMLElementB
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):