Adobe InDesign CS6 Server (8.0) Object Model JS: XML

InDesign Server CS6

Class

XML

 Wraps XML into an object.

QuickLinks

XML, addNamespace, appendChild, attribute, attributes, child, childIndex, children, comments, contains, copy, defaultSettings, descendants, elements, hasComplexContent, hasSimpleContent, inScopeNamespaces, insertChildAfter, insertChildBefore, length, localName, name, namespace, namespaceDeclarations, nodeKind, normalize, parent, prependChild, processingInstructions, removeNamespace, replace, setChildren, setLocalName, setName, setNamespace, setSettings, settings, text, toString, toXMLString, xpath

Class

PropertyTypeAccessDescription
ignoreCommentsbool r/wControls whether XML comments should be parsed (false) or ignored (true). (default: true)
ignoreProcessingInstructionsbool r/wControls whether XML preprocessing instructions should be parsed (false) or ignored (true). (default: true)
ignoreWhitespacebool r/wControls whether whitespace should be parsed (false) or ignored (true). (default: true)
prettyIndentnumber r/wThe number of spaces used to indent pretty-printed XML. (default: 2)
prettyPrintingbool r/wWhen true, XML is pretty-printed when converting to a string. (default: true)

Methods

Constructor

XML XML (text: string)
Parses an XML string. Throws an error if the XML is incorrect.

ParameterTypeDescription
textstringThe text to parse.

Class

Object defaultSettings ()
Returns an object containing the default parsing and print settings for XML.

void setSettings (obj: Object)
Sets the parsing and print setting for XML using an object returned by the settings() method.

ParameterTypeDescription
objObjectThe object containing the settings to set.

Object settings ()
Returns an object containing the current parsing and print settings for XML.

Instances

XML addNamespace (namespace: Namespace)
Adds a namespace declaration to the node. Returns the XML object itself.

ParameterTypeDescription
namespaceNamespaceThe namespace to add.

XML appendChild (child: XML)
Appends the given XML to this XML as a child. Returns the XML object itself.
If the argument is not XML, creates a new XML element containing the argument as text. The element name of that new XML is the same as the last element in the original XML.

ParameterTypeDescription
childXMLThe child XML to add.

XML attribute (name: string)
Returns a list containing all attribute elements matching the given name.

ParameterTypeDescription
namestringThe attribute name to look for.

XML attributes ()
Returns a list containing all attribute elements.

XML child (name: string)
Returns a list containing all children of this XML matching the given element name.
If the argument is a number, uses the number as index into the array of children.

ParameterTypeDescription
namestringThe name or the index of the child element.

number childIndex ()
Returns a number representing the ordinal position of this XML object within the context of its parent.

XML children ()
Returns an XML object containing all the properties of this XML object in order.

XML comments ()
Returns an XML object containing the properties of this XML object that represent XML comments.

bool contains (xml: XML)
Checks if this XML object contains the given XML object.

ParameterTypeDescription
xmlXMLThe XML to search for.

XML copy ()
Creates a copy of this XML object.

XML descendants ([name: string])
Returns all the XML-valued descendants of this XML object with the given name.
If the name parameter is omitted, returns all descendants of this XML object.

ParameterTypeDescription
namestringThe name of the descendant to find. (Optional)

XML elements ([name: string])
Returns a list of XML children that are elements with a given name, or all children that are XML elements.

ParameterTypeDescription
namestringThe element name. If not supplied, gets all children that are XML elements. (Optional)

bool hasComplexContent ()
Reports whether this XML object contains complex content.
An XML object is considered to contain complex content if it represents an XML element that has child elements. XML objects representing attributes, comments, processing instructions and text nodes do not have complex content. The existence of attributes, comments, processing instructions and text nodes within an XML object is not significant in determining if it has complex content.

bool hasSimpleContent ()
Reports whether this XML object contains simple content.
An XML object is considered to contain simple content if it represents a text node, represents an attribute node or if it represents an XML element that has no child elements. XML objects representing comments and processing instructions do not have simple content. The existence of attributes, comments, processing instructions and text nodes within an XML object is not significant in determining if it has simple content.

Array inScopeNamespaces ()
Returns an array of Namespace objects mirroring the current list of valid namespaces at this element.
The last element of the returned array is the default namespace.

void insertChildAfter (child1: XML, child2: XML)
Inserts the given child2 after the given child1 in this XML object and returns this XML object.
If child1 is null, the method inserts child2 before all children of this XML object (that is, after none of them). If child1 does not exist in this XML object, the method returns without modifying this XML object.

ParameterTypeDescription
child1XMLThe child to insert the other child after.
If null, the method inserts child2 before all children of this XML object.
child2XMLThe XML to insert.

void insertChildBefore (child1: XML, child2: XML)
Inserts the given child2 before the given child1 in this XML object and returns this XML object.
If child1 is null, the method inserts child2 after all children of this XML object (that is, before none of them). If child1 does not exist in this XML object, the method returns without modifying this XML object.

ParameterTypeDescription
child1XMLThe child to search for.
If null, the method inserts child2 after all children of this XML object.
child2XMLThe XML to insert.

number length ()
Returns the number of elements contained in an XML list. If this XML object is not a list, returns 1.

string localName ()
Returns the local name of this XML object.
This value corresponds to the element name unless the name has a namespace prefix. For example, if the element has the name "ns:tag", the return value is "tag".

QName name ()
Returns a QName object containing the URI and the local name of the element.

Namespace namespace ()
Returns a Namespace object containing the namespace URI of the current element.

Array namespaceDeclarations ()
Returns an array containing all namespace declarations of this XML object.

string nodeKind ()
Returns the type of this XML object as one of the strings "element", "attribute", "comment", "processing-instruction", or "text".

XML normalize ()
Puts all text nodes in this and all descendant XML objects into a normal form by merging adjacent text nodes and eliminating empty text nodes. Returns this XML object.

XML parent ()
Returns the parent object of this XML object.
The root object, as returned by the XML constructor, does not have a parent and returns null. Note that the E4X standard does not define what happens if this XML object is a list containing elements with multiple parents.

XML prependChild (child: XML)
Inserts a given child into this object before its existing XML properties, and returns this XML object.

ParameterTypeDescription
childXMLThe XML to insert.

XML processingInstructions ([name: string])
Returns a list of preprocessing instructions.
Collects processing-instructions with the given name, if supplied. Otherwise, returns an XML list containing all the children of this XML object that are processing-instructions regardless of their name.

ParameterTypeDescription
namestringThe name of the preprocessing instruction to return. (Optional)

XML removeNamespace (namespace: Namespace)
Removes the given namespace from this XML, and returns this XML.

ParameterTypeDescription
namespaceNamespaceThe namespace to remove.

XML replace (name: string, value: XML)
Replaces the value of specified XML properties of this XML object returns this XML object.
This method acts like the assignment operator.

ParameterTypeDescription
namestringThe property name.
Can be a numeric property name, a name for a set of XML elements, or the properties wildcard “*”. If this XML object contains no properties that match the name, the method returns without modifying this XML object.
valueXMLThe XML with which to replace the value of the matching property.
Can be an XML object, XML list or any value that can be converted to a String with toString().

XML setChildren (value: XML)
Replaces all of the XML-valued properties in this object with a new value, and returns this XML object.

ParameterTypeDescription
valueXMLThe new value, which can be a single XML object or an XML list.

void setLocalName (name: string)
Replaces the local name of this XML object with a string constructed from the given name
The local name is any part behind a colon character. If there is no colon, it is the entire name.

ParameterTypeDescription
namestringThe name to set.

void setName (name: QName)
Replaces the name of this XML object with the given QName object.

ParameterTypeDescription
nameQNameThe fully qualified name.

void setNamespace (namespace: Namespace)
Sets the namespace for this XML element.
If the namespace has not been declared in the tree above this element, adds a namespace declaration.

ParameterTypeDescription
namespaceNamespaceThe namespace to set.

XML text ()
Returns an XML list containing all XML properties of this XML object that represent XML text nodes.

string toString ()
Returns the string representation of this object.
For text and attribute nodes, this is the textual value of the node; for other elements, this is the result of calling the toXMLString() method. If this XML object is a list, concatenates the result of calling toString() on each element.

string toXMLString ()
Returns an XML-encoded string representation of this XML object.
Always includes the start tag, attributes and end tag of the XML object regardless of its content. It is provided for cases when the default XML to string conversion rules are not desired. Interprets the global settings XML.prettyPrint and XML.prettyIndent.

XML xpath (expr: string)
Evaluates the given XPath expression in accordance with the W3C XPath recommendation, using this XML object as the context node.

ParameterTypeDescription
exprstringThe XPath expression to use.

Used in:

XML XML.appendChild (child: XML)

bool XML.contains (xml: XML)

void XML.insertChildAfter (child1: XML, child2: XML)

void XML.insertChildBefore (child1: XML, child2: XML)

XML XML.prependChild (child: XML)

XML XML.replace (name: string, value: XML)

XML XML.setChildren (value: XML)

Return

XML Reflection.toXML ()

XML XML.XML (text: string)

XML XML.addNamespace (namespace: Namespace)

XML XML.appendChild (child: XML)

XML XML.attribute (name: string)

XML XML.attributes ()

XML XML.child (name: string)

XML XML.children ()

XML XML.comments ()

XML XML.copy ()

XML XML.descendants ([name: string])

XML XML.elements ([name: string])

XML XML.normalize ()

XML XML.parent ()

XML XML.prependChild (child: XML)

XML XML.processingInstructions ([name: string])

XML XML.removeNamespace (namespace: Namespace)

XML XML.replace (name: string, value: XML)

XML XML.setChildren (value: XML)

XML XML.text ()

XML XML.xpath (expr: string)

Jongware, 28-Apr-2012 v3.0.3iContents :: Index