# Titanium.XML.Document

> The DOM Document returned from [Titanium.XML.parseString](https://titaniumsdk.com/docs/sdk/Titanium.XML.md#parseString).

- Source: https://titaniumsdk.com/docs/sdk/12.6.2/Titanium.XML.Document
- Titanium SDK version: 12.6.2
- 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

Implements the [DOM Level 2 API](https://www.w3.org/TR/DOM-Level-2-Core/core.html#i-Document) 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](http://code.google.com/p/android/issues/detail?id=7395).

## Properties

### doctype

- Type: Titanium.XML.DocumentType
- Platforms: Android, iPhone, iPad, macOS
- Permission: read-only

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

- Type: Titanium.XML.Element
- Platforms: Android, iPhone, iPad, macOS
- Permission: read-only

Root element of this document.

### implementation

- Type: Titanium.XML.DOMImplementation
- Platforms: Android, iPhone, iPad, macOS
- Permission: read-only

[DOMImplementation](https://titaniumsdk.com/docs/sdk/Titanium.XML.DOMImplementation.md) object associated with this
document.

## Methods

### createAttribute

- Platforms: Android, iPhone, iPad, macOS

Creates an attribute with the given name.

Parameters:

- `name` (String): Name for the new attribute.

Returns: Titanium.XML.Attr - Attribute object, ready to be added to an element.

### createAttributeNS

- Platforms: Android, iPhone, iPad, macOS

Creates an attribute with the given name and namespace.

Parameters:

- `namespaceURI` (String): Namespace URI for the new attribute.
- `name` (String): Qualified name for the new attribute (can include a prefix).

Returns: Titanium.XML.Attr - Attribute object, ready to be added to an element.

### createCDATASection

- Platforms: Android, iPhone, iPad, macOS

Creates and returns a [CDATASection](https://titaniumsdk.com/docs/sdk/Titanium.XML.CDATASection.md).

Parameters:

- `data` (String): String data to go into the CDATA section.

Returns: Titanium.XML.CDATASection - CDATA section with the given data, ready to be added to an element.

### createComment

- Platforms: Android, iPhone, iPad, macOS

Creates a [Comment](https://titaniumsdk.com/docs/sdk/Titanium.XML.Comment.md) with the supplied string data.

Parameters:

- `data` (String): Comment text.

Returns: Titanium.XML.Comment - Comment object, ready to be appended to the DOM tree.

### createDocumentFragment

- Platforms: Android, iPhone, iPad, macOS

Creates an empty [DocumentFragment](https://titaniumsdk.com/docs/sdk/Titanium.XML.DocumentFragment.md).

Returns: Titanium.XML.DocumentFragment - The empty [Titanium.XML.DocumentFragment](https://titaniumsdk.com/docs/sdk/Titanium.XML.DocumentFragment.md).

### createElement

- Platforms: Android, iPhone, iPad, macOS

Creates an element with the given tag name.

Parameters:

- `tagName` (String): Name for the created element.

Returns: Titanium.XML.Element - Newly created element.

### createElementNS

- Platforms: Android, iPhone, iPad, macOS

Create a new element with the given namespace and name.

Parameters:

- `namespaceURI` (String): URI for the namespace the new element belongs to.
- `name` (String): Qualified for the new element (can include a prefix).

Returns: Titanium.XML.Element - New namespace-qualified element.

### createEntityReference

- Platforms: Android, iPhone, iPad, macOS

Creates an [EntityReference](https://titaniumsdk.com/docs/sdk/Titanium.XML.EntityReference.md) with the given name.

Parameters:

- `name` (String): Name for the new entity reference.

Returns: Titanium.XML.EntityReference - Newly-created entity reference.

### createProcessingInstruction

- Platforms: Android, iPhone, iPad, macOS

Creates a processing instruction for inserting into the DOM tree.

Parameters:

- `target` (String): Target part for the processing instruction.
- `data` (String): Data for the processing instruction node.

Returns: Titanium.XML.ProcessingInstruction - New processing instruction.

### createTextNode

- Platforms: Android, iPhone, iPad, macOS

Creates a text node.

Parameters:

- `data` (String): The string value for the text node.

Returns: Titanium.XML.Text - Newly-created text node.

### getElementById

- Platforms: Android, iPhone, iPad, macOS

Returns an [Element](https://titaniumsdk.com/docs/sdk/Titanium.XML.Element.md) that has an ID attribute with the given value.

Parameters:

- `elementId` (String): A unique ID value for an element to search for.

Returns: Titanium.XML.Element - The Element matching the given ID, if any.

### getElementsByTagName

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `tagname` (String): Tag name to search for.

Returns: Titanium.XML.NodeList - List of elements in the document which have the given tag name.

### getElementsByTagNameNS

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `namespaceURI` (String): Namespace URI used for matching elements.
- `localname` (String): Tag name to search for.

Returns: Titanium.XML.NodeList - List of elements in the document which belong to the given namespace and have the given tag name.

### importNode

- Platforms: Android, iPhone, iPad, macOS

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](https://titaniumsdk.com/docs/sdk/Titanium.XML.Node.md#ownerDocument)
property that points to this document, but its [parentNode](https://titaniumsdk.com/docs/sdk/Titanium.XML.Node.md#parentNode)
property is `null`, since it has not been inserted into the current document.

For more on node ownership, see [ownerDocument issues](https://www.w3.org/DOM/faq.html#ownerdoc)
in the W3C DOM FAQ.

Parameters:

- `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: Titanium.XML.Node - Imported node that belongs now to this document.

## Inherited members

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

- [Titanium.Proxy](https://titaniumsdk.com/docs/sdk/12.6.2/Titanium.Proxy.md): `addEventListener`, `apiName`, `applyProperties`, `bubbleParent`, `fireEvent`, `lifecycleContainer`, `removeEventListener`
- [Titanium.XML.Node](https://titaniumsdk.com/docs/sdk/12.6.2/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`, `text`, `textContent`

---

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

