DOM operations only raise exceptions in "exceptional" circumstances, i.e., when an operation is impossible to perform (either for logical reasons, because data is lost, or because the implementation has become unstable). In general, DOM methods return specific error values in ordinary processing situations, such as out-of-bound errors when usingNodeList.

Implementations should raise other exceptions under other circumstances. For example, implementations should raise an implementation-dependent exception if anullargument is passed.

Some languages and object systems do not support the concept of exceptions. For such systems, error conditions may be indicated using native error reporting mechanisms. For some bindings, for example, methods may return error codes similar to those listed in the corresponding method descriptions.

unsigned short

An integer indicating the type of error generated.

Other numeric codes are reserved for W3C for possible future use.

If index or size is negative, or greater than the allowed value

If the specified range of text does not fit into a DOMString

If any node is inserted somewhere it doesn't belong

If a node is used in a different document than the one that created it (that doesn't support it)

If an invalid or illegal character is specified, such as in a name. Seein the XML specification for the definition of a legal character, andfor the definition of a legal name character.

If data is specified for a node which does not support data

If an attempt is made to modify an object where modifications are not allowed

If an attempt is made to reference a node in a context where it does not exist

If the implementation does not support the requested type of object or operation.

If an attempt is made to add an attribute that is already in use elsewhere

If an attempt is made to use an object that is not, or is no longer, usable.

If an invalid or illegal string is specified.

If an attempt is made to modify the type of the underlying object.

If an attempt is made to create or change an object in a way which is incorrect with regard to namespaces.

If a parameter or an operation is not supported by the underlying object.

TheDOMImplementationinterface provides a number of methods for performing operations that are independent of any particular instance of the document object model.

Test if the DOM implementation implements a specific feature.

The name of the feature to test (case-insensitive). The values used by DOM features are defined throughout the DOM Level 2 specifications and listed in thesection. The name must be anXML name. To avoid possible conflicts, as a convention, names referring to features defined outside the DOM specification should be made unique by reversing the name of the Internet domain name of the person (or the organization that the person belongs to) who defines the feature, component by component, and using this as a prefix. For instance, the W3C SVG Working Group defines the feature "org.w3c.dom.svg".

This is the version number of the feature to test. In Level 2, the string can be either "2.0" or "1.0". If the version is not specified, supporting any version of the feature causes the method to returntrue.

trueif the feature is implemented in the specified version,falseotherwise.

Creates an emptyDocumentTypenode. Entity declarations and notations are not made available. Entity reference expansions and default attribute additions do not occur. It is expected that a future version of the DOM will provide a way for populating aDocumentType.

HTML-only DOM implementations do not need to implement this method.

Thequalified nameof the document type to be created.

The external subset public identifier.

The external subset system identifier.

A newDocumentTypenode withNode.ownerDocumentset tonull.

INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character.

NAMESPACE_ERR: Raised if thequalifiedNameis malformed.

Creates an XMLDocumentobject of the specified type with its document element. HTML-only DOM implementations do not need to implement this method.

Thenamespace URIof the document element to create.

Thequalified nameof the document element to be created.

The type of document to be created ornull.

Whendoctypeis notnull, itsNode.ownerDocumentattribute is set to the document being created.

A newDocumentobject.

INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character.

NAMESPACE_ERR: Raised if thequalifiedNameis malformed, if thequalifiedNamehas a prefix and thenamespaceURIisnull, or if thequalifiedNamehas a prefix that is "xml" and thenamespaceURIis different from "".

WRONG_DOCUMENT_ERR: Raised ifdoctypehas already been used with a different document or was created from a different implementation.

NOT_SUPPORTED_ERR: May be raised by DOM implementations which do not support the "XML" feature, if they choose not to support this method. Note: Other features introduced in the future, by the DOM WG or in extensions defined by other groups, may also demand support for this method; please consult the definition of the feature to see if it requires this method.

DocumentFragmentis a "lightweight" or "minimal"Documentobject. It is very common to want to be able to extract a portion of a document's tree or to create a new fragment of a document. Imagine implementing a user command like cut or rearranging a document by moving fragments around. It is desirable to have an object which can hold such fragments and it is quite natural to use a Node for this purpose. While it is true that aDocumentobject could fulfill this role, aDocumentobject can potentially be a heavyweight object, depending on the underlying implementation. What is really needed for this is a very lightweight object.DocumentFragmentis such an object.

Furthermore, various operations -- such as inserting nodes as children of anotherNode-- may takeDocumentFragmentobjects as arguments; this results in all the child nodes of theDocumentFragmentbeing moved to the child list of this node.

The children of aDocumentFragmentnode are zero or more nodes representing the tops of any sub-trees defining the structure of the document.DocumentFragmentnodes do not need to bewell-formed XML documents(although they do need to follow the rules imposed upon well-formed XML parsed entities, which can have multiple top nodes). For example, aDocumentFragmentmight have only one child and that child node could be aTextnode. Such a structure model represents neither an HTML document nor a well-formed XML document.

When aDocumentFragmentis inserted into aDocument(or indeed any otherNodethat may take children) the children of theDocumentFragmentand not theDocumentFragmentitself are inserted into theNode. This makes theDocumentFragmentvery useful when the user wishes to create nodes that aresiblings; theDocumentFragmentacts as the parent of these nodes so that the user can use the standard methods from theNodeinterface, such asinsertBeforeandappendChild.

TheDocumentinterface represents the entire HTML or XML document. Conceptually, it is therootof the document tree, and provides the primary access to the document's data.

Since elements, text nodes, comments, processing instructions, etc. cannot exist outside the context of aDocument, theDocumentinterface also contains the factory methods needed to create these objects. TheNodeobjects created have aownerDocumentattribute which associates them with theDocumentwithin whose context they were created.

The Document Type Declaration (seeDocumentType) associated with this document. For HTML documents as well as XML documents without a document type declaration this returnsnull. The DOM Level 2 does not support editing the Document Type Declaration.docTypecannot be altered in any way, including through the use of methods inherited from theNodeinterface, such asinsertNodeorremoveNode.

TheDOMImplementationobject that handles this document. A DOM application may use objects from multiple implementations.

This is aconvenienceattribute that allows direct access to the child node that is the root element of the document. For HTML documents, this is the element with the tagName "HTML".

Creates an element of the type specified. Note that the instance returned implements theElementinterface, so attributes can be specified directly on the returned object.

In addition, if there are known attributes with default values,Attrnodes representing them are automatically created and attached to the element.

To create an element with a qualified name and namespace URI, use thecreateElementNSmethod.

The name of the element type to instantiate. For XML, this is case-sensitive. For HTML, thetagNameparameter may be provided in any case, but it must be mapped to the canonical uppercase form by the DOM implementation.

A newElementobject with thenodeNameattribute set totagName, andlocalName,prefix, andnamespaceURIset tonull.

INVALID_CHARACTER_ERR: Raised if the specified name contains an illegal character.

Creates an emptyDocumentFragmentobject.

A newDocumentFragment.

Creates aTextnode given the specified string.

The data for the node.

The newTextobject.

Creates aCommentnode given the specified string.

The data for the node.

The newCommentobject.

Creates aCDATASectionnode whose value is the specified string.

The data for theCDATASectioncontents.

The newCDATASectionobject.

NOT_SUPPORTED_ERR: Raised if this document is an HTML document.

Creates aProcessingInstructionnode given the specified name and data strings.

The target part of the processing instruction.

The data for the node.

The newProcessingInstructionobject.

INVALID_CHARACTER_ERR: Raised if the specified target contains an illegal character.

NOT_SUPPORTED_ERR: Raised if this document is an HTML document.

Creates anAttrof the given name. Note that theAttrinstance can then be set on anElementusing thesetAttributeNodemethod.

To create an attribute with a qualified name and namespace URI, use thecreateAttributeNSmethod.

The name of the attribute.

A newAttrobject with thenodeNameattribute set toname, andlocalName,prefix, andnamespaceURIset tonull. The value of the attribute is the empty string.

INVALID_CHARACTER_ERR: Raised if the specified name contains an illegal character.

Creates anEntityReferenceobject. In addition, if the referenced entity is known, the child list of theEntityReferencenode is made the same as that of the correspondingEntitynode.

If any descendant of theEntitynode has an unboundnamespace prefix, the corresponding descendant of the createdEntityReferencenode is also unbound; (itsnamespaceURIisnull). The DOM Level 2 does not support any mechanism to resolve namespace prefixes.

The name of the entity to reference.

The newEntityReferenceobject.

INVALID_CHARACTER_ERR: Raised if the specified name contains an illegal character.

NOT_SUPPORTED_ERR: Raised if this document is an HTML document.

Returns aNodeListof all theElementswith a given tag name in the order in which they are encountered in a preorder traversal of theDocumenttree.

The name of the tag to match on. The special value "*" matches all tags.

A newNodeListobject containing all the matchedElements.

Imports a node from another document to this document. The returned node has no parent; (parentNodeisnull). The source node is not altered or removed from the original document; this method creates a new copy of the source node.

For all nodes, importing a node creates a node object owned by the importing document, with attribute values identical to the source node'snodeNameandnodeType, plus the attributes related to namespaces (prefix,localName, andnamespaceURI). As in thecloneNodeoperation on aNode, the source node is not altered.

Additional information is copied as appropriate to thenodeType, attempting to mirror the behavior expected if a fragment of XML or HTML source was copied from one document to another, recognizing that the two documents may have different DTDs in the XML case. The following list describes the specifics for each type of node.

TheownerElementattribute is set tonulland thespecifiedflag is set totrueon the generatedAttr. Thedescendantsof the sourceAttrare recursively imported and the resulting nodes reassembled to form the corresponding subtree.

Note that thedeepparameter has no effect onAttrnodes; they always carry their children with them when imported.

If thedeepoption was set totrue, thedescendantsof the source element are recursively imported and the resulting nodes reassembled to form the corresponding subtree. Otherwise, this simply generates an emptyDocumentFragment.

Documentnodes cannot be imported.

DocumentTypenodes cannot be imported.

Specifiedattribute nodes of the source element are imported, and the generatedAttrnodes are attached to the generatedElement. Default attributes arenotcopied, though if the document being imported into defines default attributes for this element name, those are assigned. If theimportNodedeepparameter was set totrue, thedescendantsof the source element are recursively imported and the resulting nodes reassembled to form the corresponding subtree.

Entitynodes can be imported, however in the current release of the DOM theDocumentTypeis readonly. Ability to add these imported nodes to aDocumentTypewill be considered for addition to a future release of the DOM.

On import, thepublicId,systemId, andnotationNameattributes are copied. If adeepimport is requested, thedescendantsof the the sourceEntityare recursively imported and the resulting nodes reassembled to form the corresponding subtree.

Only theEntityReferenceitself is copied, even if adeepimport is requested, since the source and destination documents might have defined the entity differently. If the document being imported into provides a definition for this entity name, its value is assigned.

Notationnodes can be imported, however in the current release of the DOM theDocumentTypeis readonly. Ability to add these imported nodes to aDocumentTypewill be considered for addition to a future release of the DOM.

On import, thepublicIdandsystemIdattributes are copied.

Note that thedeepparameter has no effect onNotationnodes since they never have any children.

The imported node copies itstargetanddatavalues from those of the source node.

These three types of nodes inheriting fromCharacterDatacopy theirdataandlengthattributes from those of the source node.

The node to import.

Iftrue, recursively import the subtree under the specified node; iffalse, import only the node itself, as explained above. This has no effect onAttr,EntityReference, andNotationnodes.

The imported node that belongs to thisDocument.

NOT_SUPPORTED_ERR: Raised if the type of node being imported is not supported.

Creates an element of the given qualified name and namespace URI. HTML-only DOM implementations do not need to implement this method.

Thenamespace URIof the element to create.

Thequalified nameof the element type to instantiate.

A newElementobject with the following attributes:

AttributeValue
Node.nodeNamequalifiedName
Node.namespaceURInamespaceURI
Node.prefixprefix, extracted fromqualifiedName, ornullif there is no prefix
Node.localNamelocal name, extracted fromqualifiedName
Element.tagNamequalifiedName

INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character.

NAMESPACE_ERR: Raised if thequalifiedNameis malformed, if thequalifiedNamehas a prefix and thenamespaceURIisnull, or if thequalifiedNamehas a prefix that is "xml" and thenamespaceURIis different from "".

Creates an attribute of the given qualified name and namespace URI. HTML-only DOM implementations do not need to implement this method.

Thenamespace URIof the attribute to create.

Thequalified nameof the attribute to instantiate.

A newAttrobject with the following attributes:

AttributeValue
Node.nodeNamequalifiedName
Node.namespaceURInamespaceURI
Node.prefixprefix, extracted fromqualifiedName, ornullif there is no prefix
Node.localNamelocal name, extracted fromqualifiedName
Attr.namequalifiedName
Node.nodeValuethe empty string

INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character.

NAMESPACE_ERR: Raised if thequalifiedNameis malformed, if thequalifiedNamehas a prefix and thenamespaceURIisnull, if thequalifiedNamehas a prefix that is "xml" and thenamespaceURIis different from "", or if thequalifiedNameis "xmlns" and thenamespaceURIis different from "".

Returns aNodeListof all theElementswith a givenlocal nameand namespace URI in the order in which they are encountered in a preorder traversal of theDocumenttree.

Thenamespace URIof the elements to match on. The special value "*" matches all namespaces.

Thelocal nameof the elements to match on. The special value "*" matches all local names.

A newNodeListobject containing all the matchedElements.

Returns theElementwhoseIDis given byelementId. If no such element exists, returnsnull. Behavior is not defined if more than one element has thisID.

The DOM implementation must have information that says which attributes are of type ID. Attributes with the name "ID" are not of type ID unless so defined. Implementations that do not know whether attributes are of type ID or not are expected to returnnull.

The uniqueidvalue for an element.

The matching element.

TheNodeinterface is the primary datatype for the entire Document Object Model. It represents a single node in the document tree. While all objects implementing theNodeinterface expose methods for dealing with children, not all objects implementing theNodeinterface may have children. For example,Textnodes may not have children, and adding children to such nodes results in aDOMExceptionbeing raised.

The attributesnodeName,nodeValueandattributesare included as a mechanism to get at node information without casting down to the specific derived interface. In cases where there is no obvious mapping of these attributes for a specificnodeType(e.g.,nodeValuefor anElementorattributesfor aComment), this returnsnull. Note that the specialized interfaces may contain additional and more convenient mechanisms to get and set the relevant information.

An integer indicating which type of node this is.

Numeric codes up to 200 are reserved to W3C for possible future use.

The node is anElement.

The node is anAttr.

The node is aTextnode.

The node is aCDATASection.

The node is anEntityReference.

The node is anEntity.

The node is aProcessingInstruction.

The node is aComment.

The node is aDocument.

The node is aDocumentType.

The node is aDocumentFragment.

The node is aNotation.

The values ofnodeName,nodeValue, andattributesvary according to the node type as follows:
InterfacenodeNamenodeValueattributes
Attrname of attributevalue of attributenull
CDATASection#cdata-sectioncontent of the CDATA Sectionnull
Comment#commentcontent of the commentnull
Document#documentnullnull
DocumentFragment#document-fragmentnullnull
DocumentTypedocument type namenullnull
Elementtag namenullNamedNodeMap
Entityentity namenullnull
EntityReferencename of entity referencednullnull
Notationnotation namenullnull
ProcessingInstructiontargetentire content excluding the targetnull
Text#textcontent of the text nodenull

The name of this node, depending on its type; see the table above.

The value of this node, depending on its type; see the table above. When it is defined to benull, setting it has no effect.

NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.

DOMSTRING_SIZE_ERR: Raised when it would return more characters than fit in aDOMStringvariable on the implementation platform.

A code representing the type of the underlying object, as defined above.

Theparentof this node. All nodes, exceptAttr,Document,DocumentFragment,Entity, andNotationmay have a parent. However, if a node has just been created and not yet added to the tree, or if it has been removed from the tree, this isnull.

ANodeListthat contains all children of this node. If there are no children, this is aNodeListcontaining no nodes.

The first child of this node. If there is no such node, this returnsnull.

The last child of this node. If there is no such node, this returnsnull.

The node immediately preceding this node. If there is no such node, this returnsnull.

The node immediately following this node. If there is no such node, this returnsnull.

ANamedNodeMapcontaining the attributes of this node (if it is anElement) ornullotherwise.

TheDocumentobject associated with this node. This is also theDocumentobject used to create new nodes. When this node is aDocumentor aDocumentTypewhich is not used with anyDocumentyet, this isnull.

Inserts the nodenewChildbefore the existing child noderefChild. IfrefChildisnull, insertnewChildat the end of the list of children.

IfnewChildis aDocumentFragmentobject, all of its children are inserted, in the same order, beforerefChild. If thenewChildis already in the tree, it is first removed.

The node to insert.

The reference node, i.e., the node before which the new node must be inserted.

The node being inserted.

HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of thenewChildnode, or if the node to insert is one of this node'sancestors.

WRONG_DOCUMENT_ERR: Raised ifnewChildwas created from a different document than the one that created this node.

NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly or if the parent of the node being inserted is readonly.

NOT_FOUND_ERR: Raised ifrefChildis not a child of this node.

Replaces the child nodeoldChildwithnewChildin the list of children, and returns theoldChildnode.

IfnewChildis aDocumentFragmentobject,oldChildis replaced by all of theDocumentFragmentchildren, which are inserted in the same order. If thenewChildis already in the tree, it is first removed.

The new node to put in the child list.

The node being replaced in the list.

The node replaced.

HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of thenewChildnode, or if the node to put in is one of this node'sancestors.

WRONG_DOCUMENT_ERR: Raised ifnewChildwas created from a different document than the one that created this node.

NO_MODIFICATION_ALLOWED_ERR: Raised if this node or the parent of the new node is readonly.

NOT_FOUND_ERR: Raised ifoldChildis not a child of this node.

Removes the child node indicated byoldChildfrom the list of children, and returns it.

The node being removed.

The node removed.

NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

NOT_FOUND_ERR: Raised ifoldChildis not a child of this node.

Adds the nodenewChildto the end of the list of children of this node. If thenewChildis already in the tree, it is first removed.

The node to add.

If it is aDocumentFragmentobject, the entire contents of the document fragment are moved into the child list of this node

The node added.

HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of thenewChildnode, or if the node to append is one of this node'sancestors.

WRONG_DOCUMENT_ERR: Raised ifnewChildwas created from a different document than the one that created this node.

NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

Returns whether this node has any children.

trueif this node has any children,falseotherwise.

Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes. The duplicate node has no parent; (parentNodeisnull.).

Cloning anElementcopies all attributes and their values, including those generated by the XML processor to represent defaulted attributes, but this method does not copy any text it contains unless it is a deep clone, since the text is contained in a childTextnode. Cloning anAttributedirectly, as opposed to be cloned as part of anElementcloning operation, returns a specified attribute (specifiedistrue). Cloning any other type of node simply returns a copy of this node.

Note that cloning an immutable subtree results in a mutable copy, but the children of anEntityReferenceclone arereadonly. In addition, clones of unspecifiedAttrnodes are specified. And, cloningDocument,DocumentType,Entity, andNotationnodes is implementation dependent.

Iftrue, recursively clone the subtree under the specified node; iffalse, clone only the node itself (and its attributes, if it is anElement).

The duplicate node.

Puts allTextnodes in the full depth of the sub-tree underneath thisNode, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separatesTextnodes, i.e., there are neither adjacentTextnodes nor emptyTextnodes. This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded, and is useful when operations (such as XPointerlookups) that depend on a particular document tree structure are to be used.

In cases where the document containsCDATASections, the normalize operation alone may not be sufficient, since XPointers do not differentiate betweenTextnodes andCDATASectionnodes.

Tests whether the DOM implementation implements a specific feature and that feature is supported by this node.

The name of the feature to test. This is the same name which can be passed to the methodhasFeatureonDOMImplementation.

This is the version number of the feature to test. In Level 2, version 1, this is the string "2.0". If the version is not specified, supporting any version of the feature will cause the method to returntrue.

Returnstrueif the specified feature is supported on this node,falseotherwise.

Thenamespace URIof this node, ornullif it is unspecified.

This is not a computed value that is the result of a namespace lookup based on an examination of the namespace declarations in scope. It is merely the namespace URI given at creation time.

For nodes of any type other thanELEMENT_NODEandATTRIBUTE_NODEand nodes created with a DOM Level 1 method, such ascreateElementfrom theDocumentinterface, this is alwaysnull.

Per theNamespaces in XMLSpecificationan attribute does not inherit its namespace from the element it is attached to. If an attribute is not explicitly given a namespace, it simply has no namespace.

Thenamespace prefixof this node, ornullif it is unspecified.

Note that setting this attribute, when permitted, changes thenodeNameattribute, which holds thequalified name, as well as thetagNameandnameattributes of theElementandAttrinterfaces, when applicable.

Note also that changing the prefix of an attribute that is known to have a default value, does not make a new attribute with the default value and the original prefix appear, since thenamespaceURIandlocalNamedo not change.

For nodes of any type other thanELEMENT_NODEandATTRIBUTE_NODEand nodes created with a DOM Level 1 method, such ascreateElementfrom theDocumentinterface, this is alwaysnull.

INVALID_CHARACTER_ERR: Raised if the specified prefix contains an illegal character.

NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

NAMESPACE_ERR: Raised if the specifiedprefixis malformed, if thenamespaceURIof this node isnull, if the specified prefix is "xml" and thenamespaceURIof this node is different from "", if this node is an attribute and the specified prefix is "xmlns" and thenamespaceURIof this node is different from "", or if this node is an attribute and thequalifiedNameof this node is "xmlns".

Returns the local part of thequalified nameof this node.

For nodes of any type other thanELEMENT_NODEandATTRIBUTE_NODEand nodes created with a DOM Level 1 method, such ascreateElementfrom theDocumentinterface, this is alwaysnull.

Returns whether this node (if it is an element) has any attributes.

trueif this node has any attributes,falseotherwise.

TheNodeListinterface provides the abstraction of an ordered collection of nodes, without defining or constraining how this collection is implemented.NodeListobjects in the DOM arelive.

The items in theNodeListare accessible via an integral index, starting from 0.

Returns theindexth item in the collection. Ifindexis greater than or equal to the number of nodes in the list, this returnsnull.

Index into the collection.

The node at theindexth position in theNodeList, ornullif that is not a valid index.

The number of nodes in the list. The range of valid child node indices is 0 tolength-1inclusive.

Objects implementing theNamedNodeMapinterface are used to represent collections of nodes that can be accessed by name. Note thatNamedNodeMapdoes not inherit fromNodeList;NamedNodeMapsare not maintained in any particular order. Objects contained in an object implementingNamedNodeMapmay also be accessed by an ordinal index, but this is simply to allow convenient enumeration of the contents of aNamedNodeMap, and does not imply that the DOM specifies an order to these Nodes.

NamedNodeMapobjects in the DOM arelive.

Retrieves a node specified by name.

ThenodeNameof a node to retrieve.

ANode(of any type) with the specifiednodeName, ornullif it does not identify any node in this map.

Adds a node using itsnodeNameattribute. If a node with that name is already present in this map, it is replaced by the new one.

As thenodeNameattribute is used to derive the name which the node must be stored under, multiple nodes of certain types (those that have a "special" string value) cannot be stored as the names would clash. This is seen as preferable to allowing nodes to be aliased.

A node to store in this map. The node will later be accessible using the value of itsnodeNameattribute.

If the newNodereplaces an existing node the replacedNodeis returned, otherwisenullis returned.

WRONG_DOCUMENT_ERR: Raised ifargwas created from a different document than the one that created this map.

NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.

INUSE_ATTRIBUTE_ERR: Raised ifargis anAttrthat is already an attribute of anotherElementobject. The DOM user must explicitly cloneAttrnodes to re-use them in other elements.

HIERARCHY_REQUEST_ERR: Raised if an attempt is made to add a node doesn't belong in this NamedNodeMap. Examples would include trying to insert something other than an Attr node into an Element's map of attributes, or a non-Entity node into the DocumentType's map of Entities

Removes a node specified by name. When this map contains the attributes attached to an element, if the removed attribute is known to have a default value, an attribute immediately appears containing the default value as well as the corresponding namespace URI, local name, and prefix when applicable.

ThenodeNameof the node to remove.

The node removed from this map if a node with such a name exists.

NOT_FOUND_ERR: Raised if there is no node namednamein this map.

NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.

Returns theindexth item in the map. Ifindexis greater than or equal to the number of nodes in this map, this returnsnull.

Index into this map.

The node at theindexth position in the map, ornullif that is not a valid index.

The number of nodes in this map. The range of valid child node indices is0tolength-1inclusive.

Retrieves a node specified by local name and namespace URI. HTML-only DOM implementations do not need to implement this method.

Thenamespace URIof the node to retrieve.

Thelocal nameof the node to retrieve.

ANode(of any type) with the specified local name and namespace URI, ornullif they do not identify any node in this map.

Adds a node using itsnamespaceURIandlocalName. If a node with that namespace URI and that local name is already present in this map, it is replaced by the new one.

HTML-only DOM implementations do not need to implement this method.

A node to store in this map. The node will later be accessible using the value of itsnamespaceURIandlocalNameattributes.

If the newNodereplaces an existing node the replacedNodeis returned, otherwisenullis returned.

WRONG_DOCUMENT_ERR: Raised ifargwas created from a different document than the one that created this map.

NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.

INUSE_ATTRIBUTE_ERR: Raised ifargis anAttrthat is already an attribute of anotherElementobject. The DOM user must explicitly cloneAttrnodes to re-use them in other elements.

HIERARCHY_REQUEST_ERR: Raised if an attempt is made to add a node doesn't belong in this NamedNodeMap. Examples would include trying to insert something other than an Attr node into an Element's map of attributes, or a non-Entity node into the DocumentType's map of Entities

Removes a node specified by local name and namespace URI. A removed attribute may be known to have a default value when this map contains the attributes attached to an element, as returned by the attributes attribute of theNodeinterface. If so, an attribute immediately appears containing the default value as well as the corresponding namespace URI, local name, and prefix when applicable.

HTML-only DOM implementations do not need to implement this method.

Thenamespace URIof the node to remove.

Thelocal nameof the node to remove.

The node removed from this map if a node with such a local name and namespace URI exists.

NOT_FOUND_ERR: Raised if there is no node with the specifiednamespaceURIandlocalNamein this map.

NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.

TheCharacterDatainterface extends Node with a set of attributes and methods for accessing character data in the DOM. For clarity this set is defined here rather than on each object that uses these attributes and methods. No DOM objects correspond directly toCharacterData, thoughTextand others do inherit the interface from it. Alloffsetsin this interface start from0.

As explained in theDOMStringinterface, text strings in the DOM are represented in UTF-16, i.e. as a sequence of 16-bit units. In the following, the term16-bit unitsis used whenever necessary to indicate that indexing on CharacterData is done in 16-bit units.

The character data of the node that implements this interface. The DOM implementation may not put arbitrary limits on the amount of data that may be stored in aCharacterDatanode. However, implementation limits may mean that the entirety of a node's data may not fit into a singleDOMString. In such cases, the user may callsubstringDatato retrieve the data in appropriately sized pieces.

NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.

DOMSTRING_SIZE_ERR: Raised when it would return more characters than fit in aDOMStringvariable on the implementation platform.

The number of16-bit unitsthat are available throughdataand thesubstringDatamethod below. This may have the value zero, i.e.,CharacterDatanodes may be empty.

Extracts a range of data from the node.

Start offset of substring to extract.

The number of 16-bit units to extract.

The specified substring. If the sum ofoffsetandcountexceeds thelength, then all 16-bit units to the end of the data are returned.

INDEX_SIZE_ERR: Raised if the specifiedoffsetis negative or greater than the number of 16-bit units indata, or if the specifiedcountis negative.

DOMSTRING_SIZE_ERR: Raised if the specified range of text does not fit into aDOMString.

Append the string to the end of the character data of the node. Upon success,dataprovides access to the concatenation ofdataand theDOMStringspecified.

TheDOMStringto append.

NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

Insert a string at the specified16-bit unitoffset.

The character offset at which to insert.

TheDOMStringto insert.

INDEX_SIZE_ERR: Raised if the specifiedoffsetis negative or greater than the number of 16-bit units indata.

NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

Remove a range of16-bit unitsfrom the node. Upon success,dataandlengthreflect the change.

The offset from which to start removing.

The number of 16-bit units to delete. If the sum ofoffsetandcountexceedslengththen all 16-bit units fromoffsetto the end of the data are deleted.

INDEX_SIZE_ERR: Raised if the specifiedoffsetis negative or greater than the number of 16-bit units indata, or if the specifiedcountis negative.

NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

Replace the characters starting at the specified16-bit unitoffset with the specified string.

The offset from which to start replacing.

The number of 16-bit units to replace. If the sum ofoffsetandcountexceedslength, then all 16-bit units to the end of the data are replaced; (i.e., the effect is the same as aremovemethod call with the same range, followed by anappendmethod invocation).

TheDOMStringwith which the range must be replaced.

INDEX_SIZE_ERR: Raised if the specifiedoffsetis negative or greater than the number of 16-bit units indata, or if the specifiedcountis negative.

NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

TheAttrinterface represents an attribute in anElementobject. Typically the allowable values for the attribute are defined in a document type definition.

Attrobjects inherit theNodeinterface, but since they are not actually child nodes of the element they describe, the DOM does not consider them part of the document tree. Thus, theNodeattributesparentNode,previousSibling, andnextSiblinghave anullvalue forAttrobjects. The DOM takes the view that attributes are properties of elements rather than having a separate identity from the elements they are associated with; this should make it more efficient to implement such features as default attributes associated with all elements of a given type. Furthermore,Attrnodes may not be immediate children of aDocumentFragment. However, they can be associated withElementnodes contained within aDocumentFragment. In short, users and implementors of the DOM need to be aware thatAttrnodes have some things in common with other objects inheriting theNodeinterface, but they also are quite distinct.

The attribute's effective value is determined as follows: if this attribute has been explicitly assigned any value, that value is the attribute's effective value; otherwise, if there is a declaration for this attribute, and that declaration includes a default value, then that default value is the attribute's effective value; otherwise, the attribute does not exist on this element in the structure model until it has been explicitly added. Note that thenodeValueattribute on theAttrinstance can also be used to retrieve the string version of the attribute's value(s).

In XML, where the value of an attribute can contain entity references, the child nodes of theAttrnode may be eitherTextorEntityReferencenodes (when these are in use; see the description ofEntityReferencefor discussion). Because the DOM Core is not aware of attribute types, it treats all attribute values as simple strings, even if the DTD or schema declares them as havingtokenizedtypes.

Returns the name of this attribute.

If this attribute was explicitly given a value in the original document, this istrue; otherwise, it isfalse. Note that the implementation is in charge of this attribute, not the user. If the user changes the value of the attribute (even if it ends up having the same value as the default value) then thespecifiedflag is automatically flipped totrue. To re-specify the attribute as the default value from the DTD, the user must delete the attribute. The implementation will then make a new attribute available withspecifiedset tofalseand the default value (if one exists).

In summary:

If the attribute has an assigned value in the document thenspecifiedistrue, and the value is the assigned value.

If the attribute has no assigned value in the document and has a default value in the DTD, thenspecifiedisfalse, and the value is the default value in the DTD.

If the attribute has no assigned value in the document and has a value of #IMPLIED in the DTD, then the attribute does not appear in the structure model of the document.

If theownerElementattribute isnull(i.e. because it was just created or was set tonullby the various removal and cloning operations)specifiedistrue.

On retrieval, the value of the attribute is returned as a string. Character and general entity references are replaced with their values. See also the methodgetAttributeon theElementinterface.

On setting, this creates aTextnode with the unparsed contents of the string. I.e. any characters that an XML processor would recognize as markup are instead treated as literal text. See also the methodsetAttributeon theElementinterface.

NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.

TheElementnode this attribute is attached to ornullif this attribute is not in use.

TheElementinterface represents anelementin an HTML or XML document. Elements may have attributes associated with them; since theElementinterface inherits fromNode, the genericNodeinterface attributeattributesmay be used to retrieve the set of all attributes for an element. There are methods on theElementinterface to retrieve either anAttrobject by name or an attribute value by name. In XML, where an attribute value may contain entity references, anAttrobject should be retrieved to examine the possibly fairly complex sub-tree representing the attribute value. On the other hand, in HTML, where all attributes have simple string values, methods to directly access an attribute value can safely be used as aconvenience.

In DOM Level 2, the methodnormalizeis inherited from theNodeinterface where it was moved.

The name of the element. For example, in:<elementExample id="demo"> ... </elementExample> ,tagNamehas the value"elementExample". Note that this is case-preserving in XML, as are all of the operations of the DOM. The HTML DOM returns thetagNameof an HTML element in the canonical uppercase form, regardless of the case in the source HTML document.

Retrieves an attribute value by name.

The name of the attribute to retrieve.

TheAttrvalue as a string, or the empty string if that attribute does not have a specified or default value.

Adds a new attribute. If an attribute with that name is already present in the element, its value is changed to be that of the value parameter. This value is a simple string; it is not parsed as it is being set. So any markup (such as syntax to be recognized as an entity reference) is treated as literal text, and needs to be appropriately escaped by the implementation when it is written out. In order to assign an attribute value that contains entity references, the user must create anAttrnode plus anyTextandEntityReferencenodes, build the appropriate subtree, and usesetAttributeNodeto assign it as the value of an attribute.

To set an attribute with a qualified name and namespace URI, use thesetAttributeNSmethod.

The name of the attribute to create or alter.

Value to set in string form.

INVALID_CHARACTER_ERR: Raised if the specified name contains an illegal character.

NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

Removes an attribute by name. If the removed attribute is known to have a default value, an attribute immediately appears containing the default value as well as the corresponding namespace URI, local name, and prefix when applicable.

To remove an attribute by local name and namespace URI, use theremoveAttributeNSmethod.

The name of the attribute to remove.

NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

Retrieves an attribute node by name.

To retrieve an attribute node by qualified name and namespace URI, use thegetAttributeNodeNSmethod.

The name (nodeName) of the attribute to retrieve.

TheAttrnode with the specified name (nodeName) ornullif there is no such attribute.

Adds a new attribute node. If an attribute with that name (nodeName) is already present in the element, it is replaced by the new one.

To add a new attribute node with a qualified name and namespace URI, use thesetAttributeNodeNSmethod.

TheAttrnode to add to the attribute list.

If thenewAttrattribute replaces an existing attribute, the replacedAttrnode is returned, otherwisenullis returned.

WRONG_DOCUMENT_ERR: Raised ifnewAttrwas created from a different document than the one that created the element.

NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

INUSE_ATTRIBUTE_ERR: Raised ifnewAttris already an attribute of anotherElementobject. The DOM user must explicitly cloneAttrnodes to re-use them in other elements.

Removes the specified attribute node. If the removedAttrhas a default value it is immediately replaced. The replacing attribute has the same namespace URI and local name, as well as the original prefix, when applicable.

TheAttrnode to remove from the attribute list.

TheAttrnode that was removed.

NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

NOT_FOUND_ERR: Raised ifoldAttris not an attribute of the element.

Returns aNodeListof alldescendantElementswith a given tag name, in the order in which they are encountered in a preorder traversal of thisElementtree.

The name of the tag to match on. The special value "*" matches all tags.

A list of matchingElementnodes.

Retrieves an attribute value by local name and namespace URI. HTML-only DOM implementations do not need to implement this method.

Thenamespace URIof the attribute to retrieve.

Thelocal nameof the attribute to retrieve.

TheAttrvalue as a string, or the empty string if that attribute does not have a specified or default value.

Adds a new attribute. If an attribute with the same local name and namespace URI is already present on the element, its prefix is changed to be the prefix part of thequalifiedName, and its value is changed to be thevalueparameter. This value is a simple string; it is not parsed as it is being set. So any markup (such as syntax to be recognized as an entity reference) is treated as literal text, and needs to be appropriately escaped by the implementation when it is written out. In order to assign an attribute value that contains entity references, the user must create anAttrnode plus anyTextandEntityReferencenodes, build the appropriate subtree, and usesetAttributeNodeNSorsetAttributeNodeto assign it as the value of an attribute.

HTML-only DOM implementations do not need to implement this method.

Thenamespace URIof the attribute to create or alter.

Thequalified nameof the attribute to create or alter.

The value to set in string form.

INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character.

NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

NAMESPACE_ERR: Raised if thequalifiedNameis malformed, if thequalifiedNamehas a prefix and thenamespaceURIisnull, if thequalifiedNamehas a prefix that is "xml" and thenamespaceURIis different from "", or if thequalifiedNameis "xmlns" and thenamespaceURIis different from "".

Removes an attribute by local name and namespace URI. If the removed attribute has a default value it is immediately replaced. The replacing attribute has the same namespace URI and local name, as well as the original prefix.

HTML-only DOM implementations do not need to implement this method.

Thenamespace URIof the attribute to remove.

Thelocal nameof the attribute to remove.

NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

Retrieves anAttrnode by local name and namespace URI. HTML-only DOM implementations do not need to implement this method.

Thenamespace URIof the attribute to retrieve.

Thelocal nameof the attribute to retrieve.

TheAttrnode with the specified attribute local name and namespace URI ornullif there is no such attribute.

Adds a new attribute. If an attribute with that local name and that namespace URI is already present in the element, it is replaced by the new one.

HTML-only DOM implementations do not need to implement this method.

TheAttrnode to add to the attribute list.

If thenewAttrattribute replaces an existing attribute with the samelocal nameandnamespace URI, the replacedAttrnode is returned, otherwisenullis returned.

WRONG_DOCUMENT_ERR: Raised ifnewAttrwas created from a different document than the one that created the element.

NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

INUSE_ATTRIBUTE_ERR: Raised ifnewAttris already an attribute of anotherElementobject. The DOM user must explicitly cloneAttrnodes to re-use them in other elements.

Returns aNodeListof all thedescendantElementswith a given local name and namespace URI in the order in which they are encountered in a preorder traversal of thisElementtree.

HTML-only DOM implementations do not need to implement this method.

Thenamespace URIof the elements to match on. The special value "*" matches all namespaces.

Thelocal nameof the elements to match on. The special value "*" matches all local names.

A newNodeListobject containing all the matchedElements.

Returnstruewhen an attribute with a given name is specified on this element or has a default value,falseotherwise.

The name of the attribute to look for.

trueif an attribute with the given name is specified on this element or has a default value,falseotherwise.

Returnstruewhen an attribute with a given local name and namespace URI is specified on this element or has a default value,falseotherwise. HTML-only DOM implementations do not need to implement this method.

Thenamespace URIof the attribute to look for.

Thelocal nameof the attribute to look for.

trueif an attribute with the given local name and namespace URI is specified or has a default value on this element,falseotherwise.

TheTextinterface inherits fromCharacterDataand represents the textual content (termedin XML) of anElementorAttr. If there is no markup inside an element's content, the text is contained in a single object implementing theTextinterface that is the only child of the element. If there is markup, it is parsed into theinformation items(elements, comments, etc.) andTextnodes that form the list of children of the element.

When a document is first made available via the DOM, there is only oneTextnode for each block of text. Users may create adjacentTextnodes that represent the contents of a given element without any intervening markup, but should be aware that there is no way to represent the separations between these nodes in XML or HTML, so they will not (in general) persist between DOM editing sessions. Thenormalize()method onNodemerges any such adjacentTextobjects into a single node for each block of text.

Breaks this node into two nodes at the specifiedoffset, keeping both in the tree assiblings. After being split, this node will contain all the content up to theoffsetpoint. A new node of the same type, which contains all the content at and after theoffsetpoint, is returned. If the original node had a parent node, the new node is inserted as the nextsiblingof the original node. When theoffsetis equal to the length of this node, the new node has no data.

The16-bit unitoffset at which to split, starting from0.

The new node, of the same type as this node.

INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than the number of 16-bit units indata.

NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

This interface inherits fromCharacterDataand represents the content of a comment, i.e., all the characters between the starting '<!--' and ending '-->'. Note that this is the definition of a comment in XML, and, in practice, HTML, although some HTML tools may implement the full SGML comment structure.

CDATA sections are used to escape blocks of text containing characters that would otherwise be regarded as markup. The only delimiter that is recognized in a CDATA section is the "]]>" string that ends the CDATA section. CDATA sections cannot be nested. Their primary purpose is for including material such as XML fragments, without needing to escape all the delimiters.

TheDOMStringattribute of theTextnode holds the text that is contained by the CDATA section. Note that thismaycontain characters that need to be escaped outside of CDATA sections and that, depending on the character encoding ("charset") chosen for serialization, it may be impossible to write out some characters as part of a CDATA section.

TheCDATASectioninterface inherits from theCharacterDatainterface through theTextinterface. AdjacentCDATASectionnodes are not merged by use of thenormalizemethod of theNodeinterface.

Because no markup is recognized within aCDATASection, character numeric references cannot be used as an escape mechanism when serializing. Therefore, action needs to be taken when serializing aCDATASectionwith a character encoding where some of the contained characters cannot be represented. Failure to do so would not produce well-formed XML.

One potential solution in the serialization process is to end the CDATA section before the character, output the character using a character reference or entity reference, and open a new CDATA section for any further characters in the text node. Note, however, that some code conversion libraries at the time of writing do not return an error or exception when a character is missing from the encoding, making the task of ensuring that data is not corrupted on serialization more difficult.

EachDocumenthas adoctypeattribute whose value is eithernullor aDocumentTypeobject. TheDocumentTypeinterface in the DOM Core provides an interface to the list of entities that are defined for the document, and little else because the effect of namespaces and the various XML schema efforts on DTD representation are not clearly understood as of this writing.

The DOM Level 2 doesn't support editingDocumentTypenodes.

The name of DTD; i.e., the name immediately following theDOCTYPEkeyword.

ANamedNodeMapcontaining the general entities, both external and internal, declared in the DTD. Parameter entities are not contained. Duplicates are discarded. For example in:<!DOCTYPE ex SYSTEM "ex.dtd" [ <!ENTITY foo "foo"> <!ENTITY bar "bar"> <!ENTITY bar "bar2"> <!ENTITY % baz "baz"> ]> <ex/>the interface provides access tofooand the first declaration ofbarbut not the second declaration ofbarorbaz. Every node in this map also implements theEntityinterface.

The DOM Level 2 does not support editing entities, thereforeentitiescannot be altered in any way.

ANamedNodeMapcontaining the notations declared in the DTD. Duplicates are discarded. Every node in this map also implements theNotationinterface.

The DOM Level 2 does not support editing notations, thereforenotationscannot be altered in any way.

The public identifier of the external subset.

The system identifier of the external subset.

The internal subset as a string.

The actual content returned depends on how much information is available to the implementation. This may vary depending on various parameters, including the XML processor used to build the document.

This interface represents a notation declared in the DTD. A notation either declares, by name, the format of an unparsed entity (seeof the XML 1.0 specification), or is used for formal declaration of processing instruction targets (seeof the XML 1.0 specification). ThenodeNameattribute inherited fromNodeis set to the declared name of the notation.

The DOM Level 1 does not support editingNotationnodes; they are thereforereadonly.

ANotationnode does not have any parent.

The public identifier of this notation. If the public identifier was not specified, this isnull.

The system identifier of this notation. If the system identifier was not specified, this isnull.

This interface represents an entity, either parsed or unparsed, in an XML document. Note that this models the entity itselfnotthe entity declaration.Entitydeclaration modeling has been left for a later Level of the DOM specification.

ThenodeNameattribute that is inherited fromNodecontains the name of the entity.

An XML processor may choose to completely expand entities before the structure model is passed to the DOM; in this case there will be noEntityReferencenodes in the document tree.

XML does not mandate that a non-validating XML processor read and process entity declarations made in the external subset or declared in external parameter entities. This means that parsed entities declared in the external subset need not be expanded by some classes of applications, and that the replacement value of the entity may not be available. When the replacement value is available, the correspondingEntitynode's child list represents the structure of that replacement text. Otherwise, the child list is empty.

The DOM Level 2 does not support editingEntitynodes; if a user wants to make changes to the contents of anEntity, every relatedEntityReferencenode has to be replaced in the structure model by a clone of theEntity's contents, and then the desired changes must be made to each of those clones instead.Entitynodes and all theirdescendantsarereadonly.

AnEntitynode does not have any parent.

If the entity contains an unboundnamespace prefix, thenamespaceURIof the corresponding node in theEntitynode subtree isnull. The same is true forEntityReferencenodes that refer to this entity, when they are created using thecreateEntityReferencemethod of theDocumentinterface. The DOM Level 2 does not support any mechanism to resolve namespace prefixes.

The public identifier associated with the entity, if specified. If the public identifier was not specified, this isnull.

The system identifier associated with the entity, if specified. If the system identifier was not specified, this isnull.

For unparsed entities, the name of the notation for the entity. For parsed entities, this isnull.

EntityReferenceobjects may be inserted into the structure model when an entity reference is in the source document, or when the user wishes to insert an entity reference. Note that character references and references to predefined entities are considered to be expanded by the HTML or XML processor so that characters are represented by their Unicode equivalent rather than by an entity reference. Moreover, the XML processor may completely expand references to entities while building the structure model, instead of providingEntityReferenceobjects. If it does provide such objects, then for a givenEntityReferencenode, it may be that there is noEntitynode representing the referenced entity. If such anEntityexists, then the subtree of theEntityReferencenode is in general a copy of theEntitynode subtree. However, this may not be true when an entity contains an unboundnamespace prefix. In such a case, because the namespace prefix resolution depends on where the entity reference is, thedescendantsof theEntityReferencenode may be bound to differentnamespace URIs.

As forEntitynodes,EntityReferencenodes and all theirdescendantsarereadonly.

TheProcessingInstructioninterface represents a "processing instruction", used in XML as a way to keep processor-specific information in the text of the document.

The target of this processing instruction. XML defines this as being the firsttokenfollowing the markup that begins the processing instruction.

The content of this processing instruction. This is from the first non white space character after the target to the character immediately preceding the?>.

NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.

Extensions to a language's native String class or interface

Returns the UTF-16 offset that corresponds to a UTF-32 offset. Used for random access.

You can always round-trip from a UTF-32 offset to a UTF-16 offset and back. You can round-trip from a UTF-16 offset to a UTF-32 offset and back if and only if the offset16 is not in the middle of a surrogate pair. Unmatched surrogates count as a single UTF-16 value.

UTF-32 offset.

UTF-16 offset

ifoffset32is out of bounds.

Returns the UTF-32 offset corresponding to a UTF-16 offset. Used for random access. To find the UTF-32 length of a string, use:len32 = findOffset32(source, source.length());

If the UTF-16 offset is into the middle of a surrogate pair, then the UTF-32 offset of theendof the pair is returned; that is, the index of the char after the end of the pair. You can always round-trip from a UTF-32 offset to a UTF-16 offset and back. You can round-trip from a UTF-16 offset to a UTF-32 offset and back if and only if the offset16 is not in the middle of a surrogate pair. Unmatched surrogates count as a single UTF-16 value.

UTF-16 offset

UTF-32 offset

if offset16 is out of bounds.