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 anull
argument 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.
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.
TheDOMImplementation
interface 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 the
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
.
true
if the feature is implemented in the specified version,false
otherwise.
Creates an emptyDocumentType
node. 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.
The
The external subset public identifier.
The external subset system identifier.
A newDocumentType
node withNode.ownerDocument
set tonull
.
INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character.
NAMESPACE_ERR: Raised if thequalifiedName
is malformed.
Creates an XMLDocument
object of the specified type with its document element. HTML-only DOM implementations do not need to implement this method.
The
The
The type of document to be created ornull
.
Whendoctype
is notnull
, itsNode.ownerDocument
attribute is set to the document being created.
A newDocument
object.
INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character.
NAMESPACE_ERR: Raised if thequalifiedName
is malformed, if thequalifiedName
has a prefix and thenamespaceURI
isnull
, or if thequalifiedName
has a prefix that is "xml" and thenamespaceURI
is different from ""
WRONG_DOCUMENT_ERR: Raised ifdoctype
has 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.
DocumentFragment
is a "lightweight" or "minimal"Document
object. 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 aDocument
object could fulfill this role, aDocument
object can potentially be a heavyweight object, depending on the underlying implementation. What is really needed for this is a very lightweight object.DocumentFragment
is such an object.
Furthermore, various operations -- such as inserting nodes as children of anotherNode
-- may takeDocumentFragment
objects as arguments; this results in all the child nodes of theDocumentFragment
being moved to the child list of this node.
The children of aDocumentFragment
node are zero or more nodes representing the tops of any sub-trees defining the structure of the document.DocumentFragment
nodes do not need to beDocumentFragment
might have only one child and that child node could be aText
node. Such a structure model represents neither an HTML document nor a well-formed XML document.
When aDocumentFragment
is inserted into aDocument
(or indeed any otherNode
that may take children) the children of theDocumentFragment
and not theDocumentFragment
itself are inserted into theNode
. This makes theDocumentFragment
very useful when the user wishes to create nodes that areDocumentFragment
acts as the parent of these nodes so that the user can use the standard methods from theNode
interface, such asinsertBefore
andappendChild
.
TheDocument
interface represents the entire HTML or XML document. Conceptually, it is the
Since elements, text nodes, comments, processing instructions, etc. cannot exist outside the context of aDocument
, theDocument
interface also contains the factory methods needed to create these objects. TheNode
objects created have aownerDocument
attribute which associates them with theDocument
within 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.docType
cannot be altered in any way, including through the use of methods inherited from theNode
interface, such asinsertNode
orremoveNode
.
TheDOMImplementation
object that handles this document. A DOM application may use objects from multiple implementations.
This is a
Creates an element of the type specified. Note that the instance returned implements theElement
interface, so attributes can be specified directly on the returned object.
In addition, if there are known attributes with default values,Attr
nodes representing them are automatically created and attached to the element.
To create an element with a qualified name and namespace URI, use thecreateElementNS
method.
The name of the element type to instantiate. For XML, this is case-sensitive. For HTML, thetagName
parameter may be provided in any case, but it must be mapped to the canonical uppercase form by the DOM implementation.
A newElement
object with thenodeName
attribute set totagName
, andlocalName
,prefix
, andnamespaceURI
set tonull
.
INVALID_CHARACTER_ERR: Raised if the specified name contains an illegal character.
Creates an emptyDocumentFragment
object.
A newDocumentFragment
.
Creates aText
node given the specified string.
The data for the node.
The newText
object.
Creates aComment
node given the specified string.
The data for the node.
The newComment
object.
Creates aCDATASection
node whose value is the specified string.
The data for theCDATASection
contents.
The newCDATASection
object.
NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
Creates aProcessingInstruction
node given the specified name and data strings.
The target part of the processing instruction.
The data for the node.
The newProcessingInstruction
object.
INVALID_CHARACTER_ERR: Raised if the specified target contains an illegal character.
NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
Creates anAttr
of the given name. Note that theAttr
instance can then be set on anElement
using thesetAttributeNode
method.
To create an attribute with a qualified name and namespace URI, use thecreateAttributeNS
method.
The name of the attribute.
A newAttr
object with thenodeName
attribute set toname
, andlocalName
,prefix
, andnamespaceURI
set tonull
. The value of the attribute is the empty string.
INVALID_CHARACTER_ERR: Raised if the specified name contains an illegal character.
Creates anEntityReference
object. In addition, if the referenced entity is known, the child list of theEntityReference
node is made the same as that of the correspondingEntity
node.
If any descendant of theEntity
node has an unboundEntityReference
node is also unbound; (itsnamespaceURI
isnull
). The DOM Level 2 does not support any mechanism to resolve namespace prefixes.
The name of the entity to reference.
The newEntityReference
object.
INVALID_CHARACTER_ERR: Raised if the specified name contains an illegal character.
NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
Returns aNodeList
of all theElements
with a given tag name in the order in which they are encountered in a preorder traversal of theDocument
tree.
The name of the tag to match on. The special value "*" matches all tags.
A newNodeList
object containing all the matchedElements
.
Imports a node from another document to this document. The returned node has no parent; (parentNode
isnull
). 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'snodeName
andnodeType
, plus the attributes related to namespaces (prefix
,localName
, andnamespaceURI
). As in thecloneNode
operation on aNode
, the source node is not altered.
Additional information is copied as appropriate to the The Note that the If the On import, the Only the On import, the Note that the The imported node copies its These three types of nodes inheriting fromnodeType
, 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.ownerElement
attribute is set tonull
and thespecified
flag is set totrue
on the generatedAttr
. TheAttr
are recursively imported and the resulting nodes reassembled to form the corresponding subtree.deep
parameter has no effect onAttr
nodes; they always carry their children with them when imported.deep
option was set totrue
, theDocumentFragment
.Document
nodes cannot be imported.DocumentType
nodes cannot be imported.Attr
nodes are attached to the generatedElement
. Default attributes areimportNode
deep
parameter was set totrue
, theEntity
nodes can be imported, however in the current release of the DOM theDocumentType
is readonly. Ability to add these imported nodes to aDocumentType
will be considered for addition to a future release of the DOM.publicId
,systemId
, andnotationName
attributes are copied. If adeep
import is requested, theEntity
are recursively imported and the resulting nodes reassembled to form the corresponding subtree.EntityReference
itself is copied, even if adeep
import 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.Notation
nodes can be imported, however in the current release of the DOM theDocumentType
is readonly. Ability to add these imported nodes to aDocumentType
will be considered for addition to a future release of the DOM.publicId
andsystemId
attributes are copied.deep
parameter has no effect onNotation
nodes since they never have any children.target
anddata
values from those of the source node.CharacterData
copy theirdata
andlength
attributes 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
, andNotation
nodes.
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.
The
The
A newElement
object with the following attributes:
Attribute | Value |
---|---|
Node.nodeName | qualifiedName |
Node.namespaceURI | namespaceURI |
Node.prefix | prefix, extracted fromqualifiedName , ornull if there is no prefix |
Node.localName | qualifiedName |
Element.tagName | qualifiedName |
INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character.
NAMESPACE_ERR: Raised if thequalifiedName
is malformed, if thequalifiedName
has a prefix and thenamespaceURI
isnull
, or if thequalifiedName
has a prefix that is "xml" and thenamespaceURI
is different from ""
Creates an attribute of the given qualified name and namespace URI. HTML-only DOM implementations do not need to implement this method.
The
The
A newAttr
object with the following attributes:
Attribute | Value |
---|---|
Node.nodeName | qualifiedName |
Node.namespaceURI | namespaceURI |
Node.prefix | prefix, extracted fromqualifiedName , ornull if there is no prefix |
Node.localName | qualifiedName |
Attr.name | qualifiedName |
Node.nodeValue | the empty string |
INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character.
NAMESPACE_ERR: Raised if thequalifiedName
is malformed, if thequalifiedName
has a prefix and thenamespaceURI
isnull
, if thequalifiedName
has a prefix that is "xml" and thenamespaceURI
is different from "", or if thequalifiedName
is "xmlns" and thenamespaceURI
is different from "".
Returns aNodeList
of all theElements
with a givenDocument
tree.
The
The
A newNodeList
object containing all the matchedElements
.
Returns the 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 returnElement
whoseID
is given byelementId
. If no such element exists, returnsnull
. Behavior is not defined if more than one element has thisID
.null
.
The uniqueid
value for an element.
The matching element.
TheNode
interface is the primary datatype for the entire Document Object Model. It represents a single node in the document tree. While all objects implementing theNode
interface expose methods for dealing with children, not all objects implementing theNode
interface may have children. For example,Text
nodes may not have children, and adding children to such nodes results in aDOMException
being raised.
The attributesnodeName
,nodeValue
andattributes
are 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.,nodeValue
for anElement
orattributes
for 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 aText
node.
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
, andattributes
vary according to the node type as follows:
Interface | nodeName | nodeValue | attributes |
---|---|---|---|
Attr | name of attribute | value of attribute | null |
CDATASection | #cdata-section | content of the CDATA Section | null |
Comment | #comment | content of the comment | null |
Document | #document | null | null |
DocumentFragment | #document-fragment | null | null |
DocumentType | document type name | null | null |
Element | tag name | null | NamedNodeMap |
Entity | entity name | null | null |
EntityReference | name of entity referenced | null | null |
Notation | notation name | null | null |
ProcessingInstruction | target | entire content excluding the target | null |
Text | #text | content of the text node | null |
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 aDOMString
variable on the implementation platform.
A code representing the type of the underlying object, as defined above.
TheAttr
,Document
,DocumentFragment
,Entity
, andNotation
may 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
.
ANodeList
that contains all children of this node. If there are no children, this is aNodeList
containing 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
.
ANamedNodeMap
containing the attributes of this node (if it is anElement
) ornull
otherwise.
TheDocument
object associated with this node. This is also theDocument
object used to create new nodes. When this node is aDocument
or aDocumentType
which is not used with anyDocument
yet, this isnull
.
Inserts the nodenewChild
before the existing child noderefChild
. IfrefChild
isnull
, insertnewChild
at the end of the list of children.
IfnewChild
is aDocumentFragment
object, all of its children are inserted, in the same order, beforerefChild
. If thenewChild
is 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 thenewChild
node, or if the node to insert is one of this node's
WRONG_DOCUMENT_ERR: Raised ifnewChild
was 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 ifrefChild
is not a child of this node.
Replaces the child nodeoldChild
withnewChild
in the list of children, and returns theoldChild
node.
IfnewChild
is aDocumentFragment
object,oldChild
is replaced by all of theDocumentFragment
children, which are inserted in the same order. If thenewChild
is 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 thenewChild
node, or if the node to put in is one of this node's
WRONG_DOCUMENT_ERR: Raised ifnewChild
was 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 ifoldChild
is not a child of this node.
Removes the child node indicated byoldChild
from 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 ifoldChild
is not a child of this node.
Adds the nodenewChild
to the end of the list of children of this node. If thenewChild
is already in the tree, it is first removed.
The node to add.
If it is aDocumentFragment
object, 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 thenewChild
node, or if the node to append is one of this node's
WRONG_DOCUMENT_ERR: Raised ifnewChild
was 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.
true
if this node has any children,false
otherwise.
Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes. The duplicate node has no parent; (parentNode
isnull
.).
Cloning anElement
copies 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 childText
node. Cloning anAttribute
directly, as opposed to be cloned as part of anElement
cloning operation, returns a specified attribute (specified
istrue
). 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 anEntityReference
clone areAttr
nodes are specified. And, cloningDocument
,DocumentType
,Entity
, andNotation
nodes 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 allText
nodes 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) separatesText
nodes, i.e., there are neither adjacentText
nodes nor emptyText
nodes. 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 XPointer
In cases where the document containsCDATASections
, the normalize operation alone may not be sufficient, since XPointers do not differentiate betweenText
nodes andCDATASection
nodes.
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 methodhasFeature
onDOMImplementation
.
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
.
Returnstrue
if the specified feature is supported on this node,false
otherwise.
Thenull
if 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_NODE
andATTRIBUTE_NODE
and nodes created with a DOM Level 1 method, such ascreateElement
from theDocument
interface, this is alwaysnull
.
Per the
Thenull
if it is unspecified.
Note that setting this attribute, when permitted, changes thenodeName
attribute, which holds thetagName
andname
attributes of theElement
andAttr
interfaces, 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 thenamespaceURI
andlocalName
do not change.
For nodes of any type other thanELEMENT_NODE
andATTRIBUTE_NODE
and nodes created with a DOM Level 1 method, such ascreateElement
from theDocument
interface, 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 specifiedprefix
is malformed, if thenamespaceURI
of this node isnull
, if the specified prefix is "xml" and thenamespaceURI
of this node is different from "", if this node is an attribute and the specified prefix is "xmlns" and thenamespaceURI
of this node is different from "", or if this node is an attribute and thequalifiedName
of this node is "xmlns"
Returns the local part of the
For nodes of any type other thanELEMENT_NODE
andATTRIBUTE_NODE
and nodes created with a DOM Level 1 method, such ascreateElement
from theDocument
interface, this is alwaysnull
.
Returns whether this node (if it is an element) has any attributes.
true
if this node has any attributes,false
otherwise.
TheNodeList
interface provides the abstraction of an ordered collection of nodes, without defining or constraining how this collection is implemented.NodeList
objects in the DOM are
The items in theNodeList
are accessible via an integral index, starting from 0.
Returns theindex
th item in the collection. Ifindex
is greater than or equal to the number of nodes in the list, this returnsnull
.
Index into the collection.
The node at theindex
th position in theNodeList
, ornull
if that is not a valid index.
The number of nodes in the list. The range of valid child node indices is 0 tolength-1
inclusive.
Objects implementing theNamedNodeMap
interface are used to represent collections of nodes that can be accessed by name. Note thatNamedNodeMap
does not inherit fromNodeList
;NamedNodeMaps
are not maintained in any particular order. Objects contained in an object implementingNamedNodeMap
may 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.
NamedNodeMap
objects in the DOM are
Retrieves a node specified by name.
ThenodeName
of a node to retrieve.
ANode
(of any type) with the specifiednodeName
, ornull
if it does not identify any node in this map.
Adds a node using itsnodeName
attribute. If a node with that name is already present in this map, it is replaced by the new one.
As thenodeName
attribute 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 itsnodeName
attribute.
If the newNode
replaces an existing node the replacedNode
is returned, otherwisenull
is returned.
WRONG_DOCUMENT_ERR: Raised ifarg
was 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 ifarg
is anAttr
that is already an attribute of anotherElement
object. The DOM user must explicitly cloneAttr
nodes 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.
ThenodeName
of 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 namedname
in this map.
NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
Returns theindex
th item in the map. Ifindex
is greater than or equal to the number of nodes in this map, this returnsnull
.
Index into this map.
The node at theindex
th position in the map, ornull
if that is not a valid index.
The number of nodes in this map. The range of valid child node indices is0
tolength-1
inclusive.
Retrieves a node specified by local name and namespace URI. HTML-only DOM implementations do not need to implement this method.
The
The
ANode
(of any type) with the specified local name and namespace URI, ornull
if they do not identify any node in this map.
Adds a node using itsnamespaceURI
andlocalName
. 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 itsnamespaceURI
andlocalName
attributes.
If the newNode
replaces an existing node the replacedNode
is returned, otherwisenull
is returned.
WRONG_DOCUMENT_ERR: Raised ifarg
was 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 ifarg
is anAttr
that is already an attribute of anotherElement
object. The DOM user must explicitly cloneAttr
nodes 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 theNode
interface. 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.
The
The
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 specifiednamespaceURI
andlocalName
in this map.
NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
TheCharacterData
interface 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
, thoughText
and others do inherit the interface from it. Alloffsets
in this interface start from0
.
As explained in theDOMString
interface, text strings in the DOM are represented in UTF-16, i.e. as a sequence of 16-bit units. In the following, the term
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 aCharacterData
node. 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 callsubstringData
to 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 aDOMString
variable on the implementation platform.
The number ofdata
and thesubstringData
method below. This may have the value zero, i.e.,CharacterData
nodes 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 ofoffset
andcount
exceeds thelength
, then all 16-bit units to the end of the data are returned.
INDEX_SIZE_ERR: Raised if the specifiedoffset
is negative or greater than the number of 16-bit units indata
, or if the specifiedcount
is 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,data
provides access to the concatenation ofdata
and theDOMString
specified.
TheDOMString
to append.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
Insert a string at the specified
The character offset at which to insert.
TheDOMString
to insert.
INDEX_SIZE_ERR: Raised if the specifiedoffset
is negative or greater than the number of 16-bit units indata
.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
Remove a range ofdata
andlength
reflect the change.
The offset from which to start removing.
The number of 16-bit units to delete. If the sum ofoffset
andcount
exceedslength
then all 16-bit units fromoffset
to the end of the data are deleted.
INDEX_SIZE_ERR: Raised if the specifiedoffset
is negative or greater than the number of 16-bit units indata
, or if the specifiedcount
is negative.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
Replace the characters starting at the specified
The offset from which to start replacing.
The number of 16-bit units to replace. If the sum ofoffset
andcount
exceedslength
, then all 16-bit units to the end of the data are replaced; (i.e., the effect is the same as aremove
method call with the same range, followed by anappend
method invocation).
TheDOMString
with which the range must be replaced.
INDEX_SIZE_ERR: Raised if the specifiedoffset
is negative or greater than the number of 16-bit units indata
, or if the specifiedcount
is negative.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
TheAttr
interface represents an attribute in anElement
object. Typically the allowable values for the attribute are defined in a document type definition.
Attr
objects inherit theNode
interface, 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, theNode
attributesparentNode
,previousSibling
, andnextSibling
have anull
value forAttr
objects. 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,Attr
nodes may not be immediate children of aDocumentFragment
. However, they can be associated withElement
nodes contained within aDocumentFragment
. In short, users and implementors of the DOM need to be aware thatAttr
nodes have some things in common with other objects inheriting theNode
interface, 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 thenodeValue
attribute on theAttr
instance 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 theAttr
node may be eitherText
orEntityReference
nodes (when these are in use; see the description ofEntityReference
for 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 having
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 thespecified
flag 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 withspecified
set tofalse
and the default value (if one exists).
In summary: If the attribute has an assigned value in the document then If the attribute has no assigned value in the document and has a default value in the DTD, then 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 thespecified
istrue
, and the value is the assigned value.specified
isfalse
, and the value is the default value in the DTD.ownerElement
attribute isnull
(i.e. because it was just created or was set tonull
by the various removal and cloning operations)specified
istrue
.
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 methodgetAttribute
on theElement
interface.
On setting, this creates aText
node 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 methodsetAttribute
on theElement
interface.
NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
TheElement
node this attribute is attached to ornull
if this attribute is not in use.
TheElement
interface represents anElement
interface inherits fromNode
, the genericNode
interface attributeattributes
may be used to retrieve the set of all attributes for an element. There are methods on theElement
interface to retrieve either anAttr
object by name or an attribute value by name. In XML, where an attribute value may contain entity references, anAttr
object 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 a
In DOM Level 2, the methodnormalize
is inherited from theNode
interface where it was moved.
The name of the element. For example, in:tagName
has the value"elementExample"
. Note that this is case-preserving in XML, as are all of the operations of the DOM. The HTML DOM returns thetagName
of 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.
TheAttr
value 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 anAttr
node plus anyText
andEntityReference
nodes, build the appropriate subtree, and usesetAttributeNode
to assign it as the value of an attribute.
To set an attribute with a qualified name and namespace URI, use thesetAttributeNS
method.
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 theremoveAttributeNS
method.
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 thegetAttributeNodeNS
method.
The name (nodeName
) of the attribute to retrieve.
TheAttr
node with the specified name (nodeName
) ornull
if 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 thesetAttributeNodeNS
method.
TheAttr
node to add to the attribute list.
If thenewAttr
attribute replaces an existing attribute, the replacedAttr
node is returned, otherwisenull
is returned.
WRONG_DOCUMENT_ERR: Raised ifnewAttr
was 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 ifnewAttr
is already an attribute of anotherElement
object. The DOM user must explicitly cloneAttr
nodes to re-use them in other elements.
Removes the specified attribute node. If the removedAttr
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, when applicable.
TheAttr
node to remove from the attribute list.
TheAttr
node that was removed.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
NOT_FOUND_ERR: Raised ifoldAttr
is not an attribute of the element.
Returns aNodeList
of allElements
with a given tag name, in the order in which they are encountered in a preorder traversal of thisElement
tree.
The name of the tag to match on. The special value "*" matches all tags.
A list of matchingElement
nodes.
Retrieves an attribute value by local name and namespace URI. HTML-only DOM implementations do not need to implement this method.
The
The
TheAttr
value 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 thevalue
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 anAttr
node plus anyText
andEntityReference
nodes, build the appropriate subtree, and usesetAttributeNodeNS
orsetAttributeNode
to assign it as the value of an attribute.
HTML-only DOM implementations do not need to implement this method.
The
The
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 thequalifiedName
is malformed, if thequalifiedName
has a prefix and thenamespaceURI
isnull
, if thequalifiedName
has a prefix that is "xml" and thenamespaceURI
is different from "", or if thequalifiedName
is "xmlns" and thenamespaceURI
is 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.
The
The
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
Retrieves anAttr
node by local name and namespace URI. HTML-only DOM implementations do not need to implement this method.
The
The
TheAttr
node with the specified attribute local name and namespace URI ornull
if 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.
TheAttr
node to add to the attribute list.
If thenewAttr
attribute replaces an existing attribute with the sameAttr
node is returned, otherwisenull
is returned.
WRONG_DOCUMENT_ERR: Raised ifnewAttr
was 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 ifnewAttr
is already an attribute of anotherElement
object. The DOM user must explicitly cloneAttr
nodes to re-use them in other elements.
Returns aNodeList
of all theElements
with a given local name and namespace URI in the order in which they are encountered in a preorder traversal of thisElement
tree.
HTML-only DOM implementations do not need to implement this method.
The
The
A newNodeList
object containing all the matchedElements
.
Returnstrue
when an attribute with a given name is specified on this element or has a default value,false
otherwise.
The name of the attribute to look for.
true
if an attribute with the given name is specified on this element or has a default value,false
otherwise.
Returnstrue
when an attribute with a given local name and namespace URI is specified on this element or has a default value,false
otherwise. HTML-only DOM implementations do not need to implement this method.
The
The
true
if an attribute with the given local name and namespace URI is specified or has a default value on this element,false
otherwise.
TheText
interface inherits fromCharacterData
and represents the textual content (termedin XML) of anElement
orAttr
. If there is no markup inside an element's content, the text is contained in a single object implementing theText
interface that is the only child of the element. If there is markup, it is parsed into theText
nodes that form the list of children of the element.
When a document is first made available via the DOM, there is only oneText
node for each block of text. Users may create adjacentText
nodes 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 onNode
merges any such adjacentText
objects into a single node for each block of text.
Breaks this node into two nodes at the specifiedoffset
, keeping both in the tree asoffset
point. A new node of the same type, which contains all the content at and after theoffset
point, is returned. If the original node had a parent node, the new node is inserted as the nextoffset
is equal to the length of this node, the new node has no data.
The0
.
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 fromCharacterData
and 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.
TheDOMString
attribute of theText
node holds the text that is contained by the CDATA section. Note that this
TheCDATASection
interface inherits from theCharacterData
interface through theText
interface. AdjacentCDATASection
nodes are not merged by use of thenormalize
method of theNode
interface.
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 aCDATASection
with 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.
EachDocument
has adoctype
attribute whose value is eithernull
or aDocumentType
object. TheDocumentType
interface 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 editingDocumentType
nodes.
The name of DTD; i.e., the name immediately following theDOCTYPE
keyword.
ANamedNodeMap
containing the general entities, both external and internal, declared in the DTD. Parameter entities are not contained. Duplicates are discarded. For example in:foo
and the first declaration ofbar
but not the second declaration ofbar
orbaz
. Every node in this map also implements theEntity
interface.
The DOM Level 2 does not support editing entities, thereforeentities
cannot be altered in any way.
ANamedNodeMap
containing the notations declared in the DTD. Duplicates are discarded. Every node in this map also implements theNotation
interface.
The DOM Level 2 does not support editing notations, thereforenotations
cannot 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 specificationnodeName
attribute inherited fromNode
is set to the declared name of the notation.
The DOM Level 1 does not support editingNotation
nodes; they are therefore
ANotation
node 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 itselfEntity
declaration modeling has been left for a later Level of the DOM specification.
ThenodeName
attribute that is inherited fromNode
contains 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 noEntityReference
nodes 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 correspondingEntity
node's child list represents the structure of that replacement text. Otherwise, the child list is empty.
The DOM Level 2 does not support editingEntity
nodes; if a user wants to make changes to the contents of anEntity
, every relatedEntityReference
node 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.Entity
nodes and all their
AnEntity
node does not have any parent.
If the entity contains an unboundnamespaceURI
of the corresponding node in theEntity
node subtree isnull
. The same is true forEntityReference
nodes that refer to this entity, when they are created using thecreateEntityReference
method of theDocument
interface. 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
.
EntityReference
objects 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 providingEntityReference
objects. If it does provide such objects, then for a givenEntityReference
node, it may be that there is noEntity
node representing the referenced entity. If such anEntity
exists, then the subtree of theEntityReference
node is in general a copy of theEntity
node subtree. However, this may not be true when an entity contains an unboundEntityReference
node may be bound to different
As forEntity
nodes,EntityReference
nodes and all their
TheProcessingInstruction
interface 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 first
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
ifoffset32
is 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:
If the UTF-16 offset is into the middle of a surrogate pair, then the UTF-32 offset of the
UTF-16 offset
UTF-32 offset
if offset16 is out of bounds.