# Titanium.XML.Element

> Represents an element in a DOM document, a [Titanium.XML.Node](https://titaniumsdk.com/docs/sdk/Titanium.XML.Node.md) defined by a start-tag and end-tag (or an empty tag). Elements may have [attributes](https://titaniumsdk.com/docs/sdk/Titanium.XML.Attr.md) associated with them. Implements the [DOM Level 2 API](https://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-745549614) on Android and iOS with some non-standard extensions.

- Source: https://titaniumsdk.com/docs/sdk/12.5.0/Titanium.XML.Element
- Titanium SDK version: 12.5.0
- Kind: proxy
- Platforms: Android, iPhone, iPad, macOS
- Since: Titanium SDK Android 0.9, iPhone 0.9, iPad 0.9, macOS 9.2.0
- Extends: Titanium.XML.Node
- Inheritance: Titanium.XML.Node > Titanium.Proxy

## Properties

### tagName

- Type: String
- Platforms: Android, iPhone, iPad, macOS
- Permission: read-only

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

### text

- Type: String
- Platforms: Android, iPhone, iPad, macOS
- Permission: read-only
- DEPRECATED since 2.0.0. Use [Titanium.XML.Element.textContent](Titanium.XML.Element.textContent) instead.

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

### textContent

- Type: String
- Platforms: Android, iPhone, iPad, macOS
- Permission: read-only

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

On Android, `textContent` is supported on [Element](https://titaniumsdk.com/docs/sdk/Titanium.XML.Element.md) and
[Text](https://titaniumsdk.com/docs/sdk/Titanium.XML.Text.md) nodes only.

## Methods

### getAttribute

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `name` (String): The name of the attribute

Returns: String - The [Titanium.XML.Attr](https://titaniumsdk.com/docs/sdk/Titanium.XML.Attr.md) value as a string, or empty string if the attribute has no specified or default value.

### getAttributeNode

- Platforms: Android, iPhone, iPad, macOS

Retrieves an attribute value by name, returning it as a [Titanium.XML.Attr](https://titaniumsdk.com/docs/sdk/Titanium.XML.Attr.md) object.

Parameters:

- `name` (String): The name of the attribute

Returns: Titanium.XML.Attr - The [Titanium.XML.Attr](https://titaniumsdk.com/docs/sdk/Titanium.XML.Attr.md) value, or null if there is no such attribute.

### getAttributeNodeNS

- Platforms: Android, iPhone, iPad, macOS

Retrieves an attribute value by local name and namespace URI, returning it as a [Titanium.XML.Attr](https://titaniumsdk.com/docs/sdk/Titanium.XML.Attr.md) object.

Parameters:

- `namespaceURI` (String): The namespace URI of the attribute to retrieve.
- `localName` (String): The local name of the attribute to retrieve.

Returns: Titanium.XML.Attr - The [Titanium.XML.Attr](https://titaniumsdk.com/docs/sdk/Titanium.XML.Attr.md) value, or null if there is no such attribute.

### getAttributeNS

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `namespaceURI` (String): The namespace URI of the attribute to retrieve.
- `localName` (String): The local name of the attribute to retrieve.

Returns: String - The [Titanium.XML.Attr](https://titaniumsdk.com/docs/sdk/Titanium.XML.Attr.md) value as a string, or empty string if the attribute has no specified or default value.

### getElementsByTagName

- Platforms: Android, iPhone, iPad, macOS

Retrieves a [Titanium.XML.NodeList](https://titaniumsdk.com/docs/sdk/Titanium.XML.NodeList.md) of all descendant elements with a given tag name, in preorder traversal.

Parameters:

- `name` (String): The name of the element. The value `*` matches all tags.

Returns: Titanium.XML.NodeList

### getElementsByTagNameNS

- Platforms: Android, iPhone, iPad, macOS

Retrieves a [Titanium.XML.NodeList](https://titaniumsdk.com/docs/sdk/Titanium.XML.NodeList.md) of all descendant elements with a given local name and namespace URI, in preorder traversal.

Parameters:

- `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: Titanium.XML.NodeList

### hasAttribute

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `name` (String): The name of the attribute to search for.

Returns: Boolean

### hasAttributeNS

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `namespaceURI` (String): The namespace URI of the attribute to search for.
- `localName` (String): The local name of the attribute to search for.

Returns: Boolean

### removeAttribute

- Platforms: Android, iPhone, iPad, macOS

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` (String): The name of the attribute to remove.

### removeAttributeNode

- Platforms: Android, iPhone, iPad, macOS

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:

- `oldAttr` (Titanium.XML.Attr): The attribute to remove.

### removeAttributeNS

- Platforms: Android, iPhone, iPad, macOS

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:

- `namespaceURI` (String): The namespace URI of the attribute to remove.
- `localName` (String): The local name of the attribute to remove.

### setAttribute

- Platforms: Android, iPhone, iPad, macOS

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` (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.

### setAttributeNode

- Platforms: Android, iPhone, iPad, macOS

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:

- `newAttr` (Titanium.XML.Attr): The attribute node to add to the element.

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

### setAttributeNodeNS

- Platforms: Android, iPhone, iPad, macOS

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:

- `newAttr` (Titanium.XML.Attr): The attribute node to add to the element.

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

### setAttributeNS

- Platforms: Android, iPhone, iPad, macOS

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:

- `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](https://www.w3.org/XML/1998/namespace) or [XMLNS](https://www.w3.org/2000/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.

## Inherited members

42 members are inherited. Each is documented on the type that declares it.

- [Titanium.Proxy](https://titaniumsdk.com/docs/sdk/12.5.0/Titanium.Proxy.md): `addEventListener`, `apiName`, `applyProperties`, `bubbleParent`, `fireEvent`, `lifecycleContainer`, `removeEventListener`
- [Titanium.XML.Node](https://titaniumsdk.com/docs/sdk/12.5.0/Titanium.XML.Node.md): `ATTRIBUTE_NODE`, `CDATA_SECTION_NODE`, `COMMENT_NODE`, `DOCUMENT_FRAGMENT_NODE`, `DOCUMENT_NODE`, `DOCUMENT_TYPE_NODE`, `ELEMENT_NODE`, `ENTITY_NODE`, `ENTITY_REFERENCE_NODE`, `NOTATION_NODE`, `PROCESSING_INSTRUCTION_NODE`, `TEXT_NODE`, `appendChild`, `attributes`, `childNodes`, `cloneNode`, `firstChild`, `hasAttributes`, `hasChildNodes`, `insertBefore`, `isSupported`, `lastChild`, `localName`, `namespaceURI`, `nextSibling`, `nodeName`, `nodeType`, `nodeValue`, `normalize`, `ownerDocument`, `parentNode`, `prefix`, `previousSibling`, `removeChild`, `replaceChild`

---

- This corpus documents Titanium SDK 13.4.1. Anything here that does not name a version describes 13.4.1.
- Titanium is maintained by TiDev. The Appcelerator toolchain is retired: there is no `appc` CLI, no Appcelerator Studio and no hosted build service. The supported CLI is `titanium` on npm, invoked as `ti`.

