Skip to content

Titanium.XML.Element

Represents an element in a DOM document, a Titanium.XML.Node defined by a start-tag and end-tag (or an empty tag). Elements may have attributes associated with them. Implements the DOM Level 2 API on Android and iOS with some non-standard extensions.

Extends: Titanium.XML.Node · Since: 0.9, 0.9, 0.9, 9.2.0 · Platforms: android, iphone, ipad, macos

Properties #

apiName#

extended

Type: 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, Button
returns Ti.UI.Button.

ATTRIBUTE_NODE#

extended

Type: Number

Used with nodeType to identify an
Attr node.

attributes#

extended

Type: Titanium.XML.NamedNodeMap

A map of this node's attributes.

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

bubbleParent#

extended

Type: 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.

CDATA_SECTION_NODE#

extended

Type: Number

Used with nodeType to identify a
CDATASection node.

childNodes#

extended

Type: Titanium.XML.NodeList

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

COMMENT_NODE#

extended

Type: Number

Used with nodeType to identify a
Comment node.

DOCUMENT_FRAGMENT_NODE#

extended

Type: Number

Used with nodeType to identify a
DocumentFragment node.

DOCUMENT_NODE#

extended

Type: Number

Used with nodeType to identify a
Document node.

DOCUMENT_TYPE_NODE#

extended

Type: Number

Used with nodeType to identify a
DocumentType node.

ELEMENT_NODE#

extended

Type: Number

Used with nodeType to identify an
Element node.

ENTITY_NODE#

extended

Type: Number

Used with nodeType to identify an
Entity node.

ENTITY_REFERENCE_NODE#

extended

Type: Number

Used with nodeType to identify an
EntityReference node.

firstChild#

extended

Type: Titanium.XML.Node

This node's first child.

lastChild#

extended

Type: Titanium.XML.Node

This node's last child.

lifecycleContainer#

extended

Type: Titanium.UI.Window, Titanium.UI.TabGroup

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#

extended

Type: 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#

extended

Type: String

Namespace URI of this node.

nextSibling#

extended

Type: Titanium.XML.Node

This node's next sibling.

nodeName#

extended

Type: 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#

extended

Type: 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#

extended

Type: 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.

NOTATION_NODE#

extended

Type: Number

Used with nodeType to identify a
Notation node.

ownerDocument#

extended

Type: 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#

extended

Type: Titanium.XML.Node

This node's parent node.

prefix#

extended

Type: String

Namespace prefix of this node.

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

previousSibling#

extended

Type: Titanium.XML.Node

This node's previous sibling.

PROCESSING_INSTRUCTION_NODE#

extended

Type: Number

Used with nodeType to identify a
ProcessingInstruction node.

tagName#

Type: String

The name of the element, as defined by its tag.

text (deprecated)#

Type: String

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

TEXT_NODE#

extended

Type: Number

Used with nodeType to identify a
Text node.

textContent#

Type: String

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

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

Methods #

addEventListener #

extended

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

Parameters:
NameTypeSummaryOptional
nameStringName of the event.No
callbackCallback<Titanium.Event>Callback function to invoke when the event is fired.No

appendChild #

extended

Appends the node newChild as a child of this node.

On iOS, appendChild is supported on Element
nodes only.

Parameters:
NameTypeSummaryOptional
newChildTitanium.XML.NodeNew node to append.No

Returns: Titanium.XML.Node — Newly-appended node.

applyProperties #

extended

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:
NameTypeSummaryOptional
propsDictionaryA dictionary of properties to apply.No

cloneNode #

extended

Returns a duplicate of this node.

Parameters:
NameTypeSummaryOptional
deepBooleanWhether or not to perform a deep copy of this node.No

Returns: Titanium.XML.Node — Cloned node.

fireEvent #

extended

Fires a synthesized event to any registered listeners.

Parameters:
NameTypeSummaryOptional
nameStringName of the event.No
eventDictionaryA dictionary of keys and values to add to the Titanium.Event object sent to the listeners.Yes

getAttribute #

Retrieves an attribute value by name, returning it as a string.

Parameters:
NameTypeSummaryOptional
nameStringThe name of the attributeNo

Returns: String — The <Titanium.XML.Attr> value as a string, or empty string if the attribute has no specified or default value.

getAttributeNode #

Retrieves an attribute value by name, returning it as a Titanium.XML.Attr object.

Parameters:
NameTypeSummaryOptional
nameStringThe name of the attributeNo

Returns: Titanium.XML.Attr — The <Titanium.XML.Attr> value, or null if there is no such attribute.

getAttributeNodeNS #

Retrieves an attribute value by local name and namespace URI, returning it as a Titanium.XML.Attr object.

Parameters:
NameTypeSummaryOptional
namespaceURIStringThe namespace URI of the attribute to retrieve.No
localNameStringThe local name of the attribute to retrieve.No

Returns: Titanium.XML.Attr — The <Titanium.XML.Attr> value, or null if there is no such attribute.

getAttributeNS #

Retrieves an attribute value by local name and namespace URI, returning it as a string.

Parameters:
NameTypeSummaryOptional
namespaceURIStringThe namespace URI of the attribute to retrieve.No
localNameStringThe local name of the attribute to retrieve.No

Returns: String — The <Titanium.XML.Attr> value as a string, or empty string if the attribute has no specified or default value.

getElementsByTagName #

Retrieves a Titanium.XML.NodeList of all descendant elements with a given tag name, in preorder traversal.

Parameters:
NameTypeSummaryOptional
nameStringThe name of the element. The value * matches all tags.No

Returns: Titanium.XML.NodeList

getElementsByTagNameNS #

Retrieves a Titanium.XML.NodeList of all descendant elements with a given local name and namespace URI, in preorder traversal.

Parameters:
NameTypeSummaryOptional
namespaceURIStringThe namespace URI of the element. The value * matches all namespaces.No
localNameStringThe local name of the element. The value * matches all local names.No

Returns: Titanium.XML.NodeList

hasAttribute #

Determines whether or not an attribute with the given name is available in the element, or has a default value.

Parameters:
NameTypeSummaryOptional
nameStringThe name of the attribute to search for.No

Returns: Boolean

hasAttributeNS #

Determines whether or not an attribute with the given name is available in the element, or has a default value.

Parameters:
NameTypeSummaryOptional
namespaceURIStringThe namespace URI of the attribute to search for.No
localNameStringThe local name of the attribute to search for.No

Returns: Boolean

hasAttributes #

extended

Returns true if this node has attributes.

Returns: Boolean — True if this node has attributes, false if it does not.

hasChildNodes #

extended

Returns true if this node has child nodes.

Returns: Boolean — True if this node has children, false if it does not.

insertBefore #

extended

Inserts the node newChild before the node refChild.

On iOS, insertBefore is supported on Element
nodes only.

Parameters:
NameTypeSummaryOptional
newChildTitanium.XML.NodeNode to insert.No
refChildTitanium.XML.NodeNode to insert newChild before.No

Returns: Titanium.XML.Node — The inserted node.

isSupported #

extended

Tests whether the DOM implementation supports a specific feature.

Parameters:
NameTypeSummaryOptional
featureStringName of the feature.No
versionStringVersion number of the feature.No

Returns: Boolean — True if the feature is supported, false if it is not.

normalize #

extended

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

removeAttribute #

Removes an attribute by name. If the attribute has a default value, it is immediately replaced with this default, including namespace URI and local name. Throws an exception if the element is read-only.

Parameters:
NameTypeSummaryOptional
nameStringThe name of the attribute to remove.No

removeAttributeNode #

Removes the specified attribute node. If the removed attribute has a default value, it is replaced immediately, with the same namespace and local name as the removed attribute, if applicable. Throws an exception if the element is read-only, or the attribute is not an attribute of the element.

Parameters:
NameTypeSummaryOptional
oldAttrTitanium.XML.AttrThe attribute to remove.No

removeAttributeNS #

Removes an attribute by local name and namespace URI. If the attribute has a default value, it is immediately replaced with this default, including namespace URI and local name. Throws an exception if the element is read-only.

Parameters:
NameTypeSummaryOptional
namespaceURIStringThe namespace URI of the attribute to remove.No
localNameStringThe local name of the attribute to remove.No

removeChild #

extended

Removes a child node from this node.

On iOS, removeChild is supported on Element
nodes only.

Parameters:
NameTypeSummaryOptional
oldChildTitanium.XML.NodeNode to remove.No

Returns: Titanium.XML.Node — Node that was removed.

removeEventListener #

extended

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:
NameTypeSummaryOptional
nameStringName of the event.No
callbackCallback<Titanium.Event>Callback function to remove. Must be the same function passed to addEventListener.No

replaceChild #

extended

Replaces the node oldChild with the node newChild.

On iOS, replaceChild is supported on Element
nodes only.

Parameters:
NameTypeSummaryOptional
newChildTitanium.XML.NodeNew node.No
oldChildTitanium.XML.NodeNode being replaced.No

Returns: Titanium.XML.Node — Node that was replaced.

setAttribute #

Adds a new attribute. Any attribute with the same name is replaced. Throws an exception if the element is read-only, or if the name contains an illegal character.

Parameters:
NameTypeSummaryOptional
nameStringThe name of the attribute.No
valueStringThe value of the attribute. This is value is not parsed as part of the assignment. Any markup is treated as literal text, and needs to be escaped.
No

setAttributeNode #

Adds a new attribute. Any attribute with the same nodeName as the argument is replaced. Throws an exception if the element is read-only, if newAttr is from a different document, or if newAttr is already an attribute of another element.

Parameters:
NameTypeSummaryOptional
newAttrTitanium.XML.AttrThe attribute node to add to the element.No

Returns: Titanium.XML.Attr — The attribute that was replaced, or `null` otherwise.

setAttributeNodeNS #

Adds a new attribute. Any attribute with the same local name and namespace URI is replaced. Throws an exception if the element is read-only, if newAttr is from a different document, or if newAttr is already an attribute of another element.

Parameters:
NameTypeSummaryOptional
newAttrTitanium.XML.AttrThe attribute node to add to the element.No

Returns: Titanium.XML.Attr — The attribute that was replaced, or `null` otherwise.

setAttributeNS #

Adds a new attribute. Any attribute with the same local name and namespace URI is present on the element is replaced, with its prefix changed to that of the qualifiedName parameter. Throws an exception if the element is read-only, if the name contains an illegal character, or if the qualified name contains an error.

Parameters:
NameTypeSummaryOptional
namespaceURIStringThe namespace URI of the attribute.No
qualifiedNameStringThe qualified name of the attribute. If it is malformed, has a prefix and namespaceURI is null, or if the prefix is xml or xmlns but does not correspond to a property defined in the XML or XMLNS specifications, then it contains an error.
No
valueStringThe value of the attribute. This is value is not parsed as part of the assignment. Any markup is treated as literal text, and needs to be escaped.
No

Titanium SDK Documentation