# Titanium.XML.Document

The DOM Document returned from parseString.

Availability
0.9
0.9
9.2.0

# Overview

Implements the DOM Level 2 API (opens new window) on Android and iOS.

As of version 3.1, Android does not truly support DTDs. A document with a DTD can be parsed, however it is not validated, its default attributes are not be automatically added into the DOM tree, and so on.

This has been reported as Android Issue #7395 (opens new window).

# Properties

# apiName READONLY

Availability
3.2.0
3.2.0
9.2.0
apiName :String

The name of the API that this proxy corresponds to.

The value of this property is the fully qualified name of the API. For example, Titanium.UI.Button returns Ti.UI.Button.


# attributes READONLY

Availability
0.9
0.9
9.2.0

A map of this node's attributes.

As defined by the DOM specification, only Titanium.XML.Element nodes have attributes. For all other node types, this property is always null.


# bubbleParent

Availability
3.0.0
3.0.0
9.2.0
bubbleParent :Boolean

Indicates if the proxy will bubble an event to its parent.

Some proxies (most commonly views) have a relationship to other proxies, often established by the add() method. For example, for a button added to a window, a click event on the button would bubble up to the window. Other common parents are table sections to their rows, table views to their sections, and scrollable views to their views. Set this property to false to disable the bubbling to the proxy's parent.

Default: true


# childNodes READONLY

Availability
0.9
0.9
9.2.0
childNodes :Titanium.XML.NodeList

A Titanium.XML.NodeList of this node's children.


# doctype READONLY

Availability
0.9
0.9
9.2.0

An interface to the list of entities that are defined for the document, such as via a Document Type Definition (DTD).

See note about Android and DTDs.


# documentElement READONLY

Availability
0.9
0.9
9.2.0
documentElement :Titanium.XML.Element

Root element of this document.


# firstChild READONLY

Availability
0.9
0.9
9.2.0
firstChild :Titanium.XML.Node

This node's first child.


# implementation READONLY

Availability
0.9
0.9
9.2.0

Titanium.XML.DOMImplementation object associated with this document.


# lastChild READONLY

Availability
0.9
0.9
9.2.0
lastChild :Titanium.XML.Node

This node's last child.


# lifecycleContainer

Availability
3.6.0

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks will also be called on the proxy. Proxies that require the activity lifecycle will need this property set to the appropriate containing Window or TabGroup.


# localName

Availability
0.9
0.9
9.2.0
localName :String

Local part of the qualified name of this node.

The local part of the qualified name that comes after the colon. That is, the name without the namespace prefix.


# namespaceURI READONLY

Availability
0.9
0.9
9.2.0
namespaceURI :String

Namespace URI of this node.


# nextSibling READONLY

Availability
0.9
0.9
9.2.0
nextSibling :Titanium.XML.Node

This node's next sibling.


# nodeName READONLY

Availability
0.9
0.9
9.2.0
nodeName :String

Name of this node.

Certain node types have constant values defined by the DOM specification:

  • Text node: #text
  • Comment node: #comment
  • CDATA section node: #cdata-section
  • Document node: #document
  • Document fragment node: #document-fragment

# nodeType READONLY

Availability
0.9
0.9
9.2.0
nodeType :Number

This node's type. One of ELEMENT_NODE, ATTRIBUTE_NODE, TEXT_NODE, CDATA_SECTION_NODE, ENTITY_REFERENCE_NODE, ENTITY_NODE, PROCESSING_INSTRUCTION_NODE, COMMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, DOCUMENT_FRAGMENT_NODE, NOTATION_NODE.


# nodeValue

Availability
0.9
0.9
9.2.0
nodeValue :String

Content (value) of this node.

As defined in the DOM specification, the node value is always null for Document, DocumentFragment, DocumentType, Element, Entity, EntityReference, and Notation nodes.


# ownerDocument READONLY

Availability
0.9
0.9
9.2.0
ownerDocument :Titanium.XML.Document

This node's owning document.

Note that a node always has an owning document, even if it is not part of the document tree.

For more on node ownership, see ownerDocument issues in the W3C DOM FAQ.


# parentNode READONLY

Availability
0.9
0.9
9.2.0
parentNode :Titanium.XML.Node

This node's parent node.


# prefix

Availability
0.9
0.9
9.2.0
prefix :String

Namespace prefix of this node.

Read-only on iOS, read-write on other platforms.


# previousSibling READONLY

Availability
0.9
0.9
9.2.0
previousSibling :Titanium.XML.Node

This node's previous sibling.


# text READONLYDEPRECATED

Availability
0.9
9.2.0
text :String

DEPRECATED SINCE 2.0.0

Use textContent instead.

Content (value) of all text nodes within this node.


# textContent READONLY

Availability
0.9
9.2.0
textContent :String

Content (value) of all text nodes within this node.

On Android, textContent is supported on Titanium.XML.Element and Titanium.XML.Text nodes only.

# Methods

# addEventListener

Availability
0.9
0.9
9.2.0
addEventListener(name, callback) void

Adds the specified callback as an event listener for the named event.

Parameters

Name Type Description
name String

Name of the event.

callback Callback<Titanium.Event>

Callback function to invoke when the event is fired.

Returns

Type
void

# appendChild

Availability
0.9
0.9
9.2.0
appendChild(newChild) Titanium.XML.Node

Appends the node newChild as a child of this node.

On iOS, appendChild is supported on Titanium.XML.Element nodes only.

Parameters

Name Type Description
newChild Titanium.XML.Node

New node to append.

Returns

Newly-appended node.


# applyProperties

Availability
3.0.0
3.0.0
9.2.0
applyProperties(props) void

Applies the properties to the proxy.

Properties are supplied as a dictionary. Each key-value pair in the object is applied to the proxy such that myproxy[key] = value.

Parameters

Name Type Description
props Dictionary

A dictionary of properties to apply.

Returns

Type
void

# cloneNode

Availability
0.9
0.9
9.2.0
cloneNode(deep) Titanium.XML.Node

Returns a duplicate of this node.

Parameters

Name Type Description
deep Boolean

Whether or not to perform a deep copy of this node.

Returns

Cloned node.


# createAttribute

Availability
0.9
0.9
9.2.0
createAttribute(name) Titanium.XML.Attr

Creates an attribute with the given name.

Parameters

Name Type Description
name String

Name for the new attribute.

Returns

Attribute object, ready to be added to an element.


# createAttributeNS

Availability
0.9
0.9
9.2.0
createAttributeNS(namespaceURI, name) Titanium.XML.Attr

Creates an attribute with the given name and namespace.

Parameters

Name Type Description
namespaceURI String

Namespace URI for the new attribute.

name String

Qualified name for the new attribute (can include a prefix).

Returns

Attribute object, ready to be added to an element.


# createCDATASection

Availability
0.9
0.9
9.2.0
createCDATASection(data) Titanium.XML.CDATASection

Creates and returns a Titanium.XML.CDATASection.

Parameters

Name Type Description
data String

String data to go into the CDATA section.

Returns

CDATA section with the given data, ready to be added to an element.


# createComment

Availability
0.9
0.9
9.2.0
createComment(data) Titanium.XML.Comment

Creates a Titanium.XML.Comment with the supplied string data.

Parameters

Name Type Description
data String

Comment text.

Returns

Comment object, ready to be appended to the DOM tree.


# createDocumentFragment

Availability
0.9
0.9
9.2.0
createDocumentFragment() Titanium.XML.DocumentFragment

Returns

The empty Titanium.XML.DocumentFragment.


# createElement

Availability
0.9
0.9
9.2.0
createElement(tagName) Titanium.XML.Element

Creates an element with the given tag name.

Parameters

Name Type Description
tagName String

Name for the created element.

Returns

Newly created element.


# createElementNS

Availability
0.9
0.9
9.2.0
createElementNS(namespaceURI, name) Titanium.XML.Element

Create a new element with the given namespace and name.

Parameters

Name Type Description
namespaceURI String

URI for the namespace the new element belongs to.

name String

Qualified for the new element (can include a prefix).

Returns

New namespace-qualified element.


# createEntityReference

Availability
0.9
0.9
9.2.0
createEntityReference(name) Titanium.XML.EntityReference

Creates an Titanium.XML.EntityReference with the given name.

Parameters

Name Type Description
name String

Name for the new entity reference.

Returns

Newly-created entity reference.


# createProcessingInstruction

Availability
0.9
0.9
9.2.0
createProcessingInstruction(target, data) Titanium.XML.ProcessingInstruction

Creates a processing instruction for inserting into the DOM tree.

Parameters

Name Type Description
target String

Target part for the processing instruction.

data String

Data for the processing instruction node.

Returns

New processing instruction.


# createTextNode

Availability
0.9
0.9
9.2.0
createTextNode(data) Titanium.XML.Text

Creates a text node.

Parameters

Name Type Description
data String

The string value for the text node.

Returns

Newly-created text node.


# fireEvent

Availability
0.9
0.9
9.2.0
fireEvent(name[, event]) void

Fires a synthesized event to any registered listeners.

Parameters

Name Type Description
name String

Name of the event.

event Dictionary

A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.

Returns

Type
void

# getElementById

Availability
0.9
0.9
9.2.0
getElementById(elementId) Titanium.XML.Element

Returns an Titanium.XML.Element that has an ID attribute with the given value.

Parameters

Name Type Description
elementId String

A unique ID value for an element to search for.

Returns

The Element matching the given ID, if any.


# getElementsByTagName

Availability
0.9
0.9
9.2.0
getElementsByTagName(tagname) Titanium.XML.NodeList

Returns a node list of elements in the document which have the given tag.

Parameters

Name Type Description
tagname String

Tag name to search for.

Returns

List of elements in the document which have the given tag name.


# getElementsByTagNameNS

Availability
0.9
0.9
9.2.0
getElementsByTagNameNS(namespaceURI, localname) Titanium.XML.NodeList

Returns a node list of elements in the document which belong to the given namespace and have the given tag name.

Parameters

Name Type Description
namespaceURI String

Namespace URI used for matching elements.

localname String

Tag name to search for.

Returns

List of elements in the document which belong to the given namespace and have the given tag name.


# hasAttributes

Availability
0.9
0.9
9.2.0
hasAttributes() Boolean

Returns true if this node has attributes.

Returns

True if this node has attributes, false if it does not.

Type
Boolean

# hasChildNodes

Availability
0.9
0.9
9.2.0
hasChildNodes() Boolean

Returns true if this node has child nodes.

Returns

True if this node has children, false if it does not.

Type
Boolean

# importNode

Availability
0.9
0.9
9.2.0
importNode(importedNode, deep) Titanium.XML.Node

Imports a node from another document to this document, without altering or removing the source node from the original document.

This method creates a new copy of the source node, ready to be inserted into this document. The returned node has an ownerDocument property that points to this document, but its parentNode property is null, since it has not been inserted into the current document.

For more on node ownership, see ownerDocument issues in the W3C DOM FAQ.

Parameters

Name Type Description
importedNode Titanium.XML.Node

Node to import.

deep Boolean

If true, recursively import the subtree under the specified node; if false, import only the node itself.

Returns

Imported node that belongs now to this document.


# insertBefore

Availability
0.9
0.9
9.2.0
insertBefore(newChild, refChild) Titanium.XML.Node

Inserts the node newChild before the node refChild.

On iOS, insertBefore is supported on Titanium.XML.Element nodes only.

Parameters

Name Type Description
newChild Titanium.XML.Node

Node to insert.

refChild Titanium.XML.Node

Node to insert newChild before.

Returns

The inserted node.


# isSupported

Availability
0.9
0.9
9.2.0
isSupported(feature, version) Boolean

Tests whether the DOM implementation supports a specific feature.

Parameters

Name Type Description
feature String

Name of the feature.

version String

Version number of the feature.

Returns

True if the feature is supported, false if it is not.

Type
Boolean

# normalize

Availability
0.9
normalize() void

Normalizes text and attribute nodes in this node's child hierarchy.

Returns

Type
void

# removeChild

Availability
0.9
0.9
9.2.0
removeChild(oldChild) Titanium.XML.Node

Removes a child node from this node.

On iOS, removeChild is supported on Titanium.XML.Element nodes only.

Parameters

Name Type Description
oldChild Titanium.XML.Node

Node to remove.

Returns

Node that was removed.


# removeEventListener

Availability
0.9
0.9
9.2.0
removeEventListener(name, callback) void

Removes the specified callback as an event listener for the named event.

Multiple listeners can be registered for the same event, so the callback parameter is used to determine which listener to remove.

When adding a listener, you must save a reference to the callback function in order to remove the listener later:

var listener = function() { Ti.API.info("Event listener called."); }
window.addEventListener('click', listener);

To remove the listener, pass in a reference to the callback function:

window.removeEventListener('click', listener);

Parameters

Name Type Description
name String

Name of the event.

callback Callback<Titanium.Event>

Callback function to remove. Must be the same function passed to addEventListener.

Returns

Type
void

# replaceChild

Availability
0.9
0.9
9.2.0
replaceChild(newChild, oldChild) Titanium.XML.Node

Replaces the node oldChild with the node newChild.

On iOS, replaceChild is supported on Titanium.XML.Element nodes only.

Parameters

Name Type Description
newChild Titanium.XML.Node

New node.

oldChild Titanium.XML.Node

Node being replaced.

Returns

Node that was replaced.

# Constants

# ATTRIBUTE_NODE

Availability
0.9
0.9
9.2.0
ATTRIBUTE_NODE :Number

Used with nodeType to identify an Titanium.XML.Attr node.


# CDATA_SECTION_NODE

Availability
0.9
0.9
9.2.0
CDATA_SECTION_NODE :Number

Used with nodeType to identify a Titanium.XML.CDATASection node.


# COMMENT_NODE

Availability
0.9
0.9
9.2.0
COMMENT_NODE :Number

Used with nodeType to identify a Titanium.XML.Comment node.


# DOCUMENT_FRAGMENT_NODE

Availability
0.9
0.9
9.2.0
DOCUMENT_FRAGMENT_NODE :Number

Used with nodeType to identify a Titanium.XML.DocumentFragment node.


# DOCUMENT_NODE

Availability
0.9
0.9
9.2.0
DOCUMENT_NODE :Number

Used with nodeType to identify a Titanium.XML.Document node.


# DOCUMENT_TYPE_NODE

Availability
0.9
0.9
9.2.0
DOCUMENT_TYPE_NODE :Number

Used with nodeType to identify a Titanium.XML.DocumentType node.


# ELEMENT_NODE

Availability
0.9
0.9
9.2.0
ELEMENT_NODE :Number

Used with nodeType to identify an Titanium.XML.Element node.


# ENTITY_NODE

Availability
0.9
0.9
9.2.0
ENTITY_NODE :Number

Used with nodeType to identify an Titanium.XML.Entity node.


# ENTITY_REFERENCE_NODE

Availability
0.9
0.9
9.2.0
ENTITY_REFERENCE_NODE :Number

Used with nodeType to identify an Titanium.XML.EntityReference node.


# NOTATION_NODE

Availability
0.9
0.9
9.2.0
NOTATION_NODE :Number

Used with nodeType to identify a Titanium.XML.Notation node.


# PROCESSING_INSTRUCTION_NODE

Availability
0.9
0.9
9.2.0
PROCESSING_INSTRUCTION_NODE :Number

Used with nodeType to identify a Titanium.XML.ProcessingInstruction node.


# TEXT_NODE

Availability
0.9
0.9
9.2.0
TEXT_NODE :Number

Used with nodeType to identify a Titanium.XML.Text node.