# 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 Titanium.XML.Attr associated with them. Implements the DOM Level 2 API on Android and iOS with some non-standard extensions.

Availability
0.9
0.9
9.2.0

# Properties

# tagName READONLY

Availability
0.9
0.9
9.2.0
tagName :String

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


# text READONLYDEPRECATED

Availability
0.9
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
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

# getAttribute

Availability
0.9
0.9
9.2.0
getAttribute(name) String

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

Parameters

Name Type Description
name String

The name of the attribute

Returns

The Titanium.XML.Attr value as a string, or empty string if the attribute has no specified or default value.

Type
String

# getAttributeNode

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

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

Parameters

Name Type Description
name String

The name of the attribute

Returns

The Titanium.XML.Attr value, or null if there is no such attribute.


# getAttributeNodeNS

Availability
0.9
0.9
9.2.0
getAttributeNodeNS(namespaceURI, localName) Titanium.XML.Attr

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

Parameters

Name Type Description
namespaceURI String

The namespace URI of the attribute to retrieve.

localName String

The local name of the attribute to retrieve.

Returns

The Titanium.XML.Attr value, or null if there is no such attribute.


# getAttributeNS

Availability
0.9
0.9
9.2.0
getAttributeNS(namespaceURI, localName) String

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

Parameters

Name Type Description
namespaceURI String

The namespace URI of the attribute to retrieve.

localName String

The local name of the attribute to retrieve.

Returns

The Titanium.XML.Attr value as a string, or empty string if the attribute has no specified or default value.

Type
String

# getElementsByTagName

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

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

Parameters

Name Type Description
name String

The name of the element. The value * matches all tags.

Returns


# getElementsByTagNameNS

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

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

Parameters

Name Type Description
namespaceURI String

The namespace URI of the element. The value * matches all namespaces.

localName String

The local name of the element. The value * matches all local names.

Returns


# hasAttribute

Availability
0.9
0.9
9.2.0
hasAttribute(name) Boolean

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

Parameters

Name Type Description
name String

The name of the attribute to search for.

Returns

Type
Boolean

# hasAttributeNS

Availability
0.9
0.9
9.2.0
hasAttributeNS(namespaceURI, localName) Boolean

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

Parameters

Name Type Description
namespaceURI String

The namespace URI of the attribute to search for.

localName String

The local name of the attribute to search for.

Returns

Type
Boolean

# removeAttribute

Availability
0.9
0.9
9.2.0
removeAttribute(name) void

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

Name Type Description
name String

The name of the attribute to remove.

Returns

Type
void

# removeAttributeNode

Availability
0.9
0.9
9.2.0
removeAttributeNode(oldAttr) void

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

Name Type Description
oldAttr Titanium.XML.Attr

The attribute to remove.

Returns

Type
void

# removeAttributeNS

Availability
0.9
0.9
9.2.0
removeAttributeNS(namespaceURI, localName) void

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

Name Type Description
namespaceURI String

The namespace URI of the attribute to remove.

localName String

The local name of the attribute to remove.

Returns

Type
void

# setAttribute

Availability
0.9
0.9
9.2.0
setAttribute(name, value) void

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

Name Type Description
name String

The name of the attribute.

value String

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

Returns

Type
void

# setAttributeNode

Availability
0.9
0.9
9.2.0
setAttributeNode(newAttr) Titanium.XML.Attr

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

Name Type Description
newAttr Titanium.XML.Attr

The attribute node to add to the element.

Returns

The attribute that was replaced, or null otherwise.


# setAttributeNodeNS

Availability
0.9
0.9
9.2.0
setAttributeNodeNS(newAttr) Titanium.XML.Attr

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

Name Type Description
newAttr Titanium.XML.Attr

The attribute node to add to the element.

Returns

The attribute that was replaced, or null otherwise.


# setAttributeNS

Availability
0.9
0.9
9.2.0
setAttributeNS(namespaceURI, qualifiedName, value) void

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

Name Type Description
namespaceURI String

The namespace URI of the attribute.

qualifiedName String

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

value String

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

Returns

Type
void