XML

Wraps XML into an object.

Methods:

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

Property Listing

Name

Type

Access

Description

ignoreComments

Boolean

readonly

Controls whether XML comments should be parsed (false) or ignored (true).

ignoreProcessingInstructions

Boolean

readonly

Controls whether XML preprocessing instructions should be parsed (false) or ignored (true).

ignoreWhitespace

Boolean

readonly

Controls whether whitespace should be parsed (false) or ignored (true).

prettyIndent

Number

readonly

The number of spaces used to indent pretty-printed XML.

prettyPrinting

Boolean

readonly

When true, XML is pretty-printed when converting to a string.

Method Listing

Constructor

XML XML (text:String)

Parses an XML string. Throws an error if the XML is incorrect.

Parameter

Type

Description

text

String

The text to parse.

XML addNamespace (namespace:Namespace)

Adds a namespace declaration to the node. Returns the XML object itself.

Parameter

Type

Description

namespace

Namespace

The 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.

Parameter

Type

Description

child

XML

The child XML to add.

XML attribute (name:String)

Returns a list containing all attribute elements matching the given name.

Parameter

Type

Description

name

String

The 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.

Parameter

Type

Description

name

String

The 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.

Boolean contains (xml:XML)

Checks if this XML object contains the given XML object.

Parameter

Type

Description

xml

XML

The XML to search for.

XML copy ()

Creates a copy of this XML object.

Object defaultSettings ()

Returns an object containing the default parsing and print settings for XML.

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.

Parameter

Type

Description

name

String

The name of the descendant to find.

XML elements ([name:String])

Returns a list of XML children that are elements with a given name, or all children that are XML elements.

Parameter

Type

Description

name

String

The element name. If not supplied, gets all children that are XML elements.

Boolean 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.

Boolean 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.

undefined 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.

Parameter

Type

Description

child1

XML

The child to insert the other child after.

If null, the method inserts child2 before all children of this XML object.

child2

XML

The XML to insert.

undefined 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.

Parameter

Type

Description

child1

XML

The child to search for.

If null, the method inserts child2 after all children of this XML object.

child2

XML

The 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.

Parameter

Type

Description

child

XML

The 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.

Parameter

Type

Description

name

String

The name of the preprocessing instruction to return.

XML removeNamespace (namespace:Namespace)

Removes the given namespace from this XML, and returns this XML.

Parameter

Type

Description

namespace

Namespace

The 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.

Parameter

Type

Description

name

String

The 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.

value

XML

The 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.

Parameter

Type

Description

value

XML

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

undefined 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.

Parameter

Type

Description

name

String

The name to set.

undefined setName (name:QName)

Replaces the name of this XML object with the given QName object.

Parameter

Type

Description

name

QName

The fully qualified name.

undefined 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.

Parameter

Type

Description

namespace

Namespace

The namespace to set.

undefined setSettings (obj:Object)

Sets the parsing and print setting for XML using an object returned by the settings() method.

Parameter

Type

Description

obj

Object

The object containing the settings to set.

Object settings ()

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

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.

Parameter

Type

Description

expr

String

The XPath expression to use.

Return

XML.addNamespace()

XML.appendChild()

XML.copy()

XML.xpath()

XML.prependChild()

XML.XML()

XML.normalize()

XML.removeNamespace()

XML.setChildren()

XML.replace()

XML.attribute()

XML.attributes()

XML.child()

XML.elements()

XML.processingInstructions()

XML.descendants()

XML.text()

XML.children()

XML.comments()

XML.parent()

Reflection.toXML()