2
* Copyright (c) 2000 World Wide Web Consortium,
3
* (Massachusetts Institute of Technology, Institut National de
4
* Recherche en Informatique et en Automatique, Keio University). All
5
* Rights Reserved. This program is distributed under the W3C's Software
6
* Intellectual Property License. This program is distributed in the
7
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even
8
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10
* See W3C License http://www.w3.org/Consortium/Legal/ for more details.
16
* The <code>Node</code> interface is the primary datatype for the entire
17
* Document Object Model. It represents a single node in the document tree.
18
* While all objects implementing the <code>Node</code> interface expose
19
* methods for dealing with children, not all objects implementing the
20
* <code>Node</code> interface may have children. For example,
21
* <code>Text</code> nodes may not have children, and adding children to
22
* such nodes results in a <code>DOMException</code> being raised.
23
* <p>The attributes <code>nodeName</code>, <code>nodeValue</code> and
24
* <code>attributes</code> are included as a mechanism to get at node
25
* information without casting down to the specific derived interface. In
26
* cases where there is no obvious mapping of these attributes for a
27
* specific <code>nodeType</code> (e.g., <code>nodeValue</code> for an
28
* <code>Element</code> or <code>attributes</code> for a <code>Comment</code>
29
* ), this returns <code>null</code>. Note that the specialized interfaces
30
* may contain additional and more convenient mechanisms to get and set the
31
* relevant information.
32
* <p>The values of <code>nodeName</code>,
33
* <code>nodeValue</code>, and <code>attributes</code> vary according to the
34
* node type as follows:
43
* <td valign='top' rowspan='1' colspan='1'>Attr</td>
44
* <td valign='top' rowspan='1' colspan='1'>name of
46
* <td valign='top' rowspan='1' colspan='1'>value of attribute</td>
47
* <td valign='top' rowspan='1' colspan='1'>null</td>
50
* <td valign='top' rowspan='1' colspan='1'>CDATASection</td>
51
* <td valign='top' rowspan='1' colspan='1'><code>"#cdata-section"</code></td>
52
* <td valign='top' rowspan='1' colspan='1'>
53
* content of the CDATA Section</td>
54
* <td valign='top' rowspan='1' colspan='1'>null</td>
57
* <td valign='top' rowspan='1' colspan='1'>Comment</td>
58
* <td valign='top' rowspan='1' colspan='1'><code>"#comment"</code></td>
59
* <td valign='top' rowspan='1' colspan='1'>content of
61
* <td valign='top' rowspan='1' colspan='1'>null</td>
64
* <td valign='top' rowspan='1' colspan='1'>Document</td>
65
* <td valign='top' rowspan='1' colspan='1'><code>"#document"</code></td>
66
* <td valign='top' rowspan='1' colspan='1'>null</td>
67
* <td valign='top' rowspan='1' colspan='1'>null</td>
70
* <td valign='top' rowspan='1' colspan='1'>DocumentFragment</td>
71
* <td valign='top' rowspan='1' colspan='1'>
72
* <code>"#document-fragment"</code></td>
73
* <td valign='top' rowspan='1' colspan='1'>null</td>
74
* <td valign='top' rowspan='1' colspan='1'>null</td>
77
* <td valign='top' rowspan='1' colspan='1'>DocumentType</td>
78
* <td valign='top' rowspan='1' colspan='1'>document type name</td>
79
* <td valign='top' rowspan='1' colspan='1'>
81
* <td valign='top' rowspan='1' colspan='1'>null</td>
84
* <td valign='top' rowspan='1' colspan='1'>Element</td>
85
* <td valign='top' rowspan='1' colspan='1'>tag name</td>
86
* <td valign='top' rowspan='1' colspan='1'>null</td>
87
* <td valign='top' rowspan='1' colspan='1'>NamedNodeMap</td>
90
* <td valign='top' rowspan='1' colspan='1'>Entity</td>
91
* <td valign='top' rowspan='1' colspan='1'>entity name</td>
92
* <td valign='top' rowspan='1' colspan='1'>null</td>
93
* <td valign='top' rowspan='1' colspan='1'>null</td>
96
* <td valign='top' rowspan='1' colspan='1'>
97
* EntityReference</td>
98
* <td valign='top' rowspan='1' colspan='1'>name of entity referenced</td>
99
* <td valign='top' rowspan='1' colspan='1'>null</td>
100
* <td valign='top' rowspan='1' colspan='1'>null</td>
103
* <td valign='top' rowspan='1' colspan='1'>Notation</td>
104
* <td valign='top' rowspan='1' colspan='1'>notation name</td>
105
* <td valign='top' rowspan='1' colspan='1'>null</td>
106
* <td valign='top' rowspan='1' colspan='1'>
110
* <td valign='top' rowspan='1' colspan='1'>ProcessingInstruction</td>
111
* <td valign='top' rowspan='1' colspan='1'>target</td>
112
* <td valign='top' rowspan='1' colspan='1'>entire content excluding the target</td>
113
* <td valign='top' rowspan='1' colspan='1'>null</td>
116
* <td valign='top' rowspan='1' colspan='1'>Text</td>
117
* <td valign='top' rowspan='1' colspan='1'>
118
* <code>"#text"</code></td>
119
* <td valign='top' rowspan='1' colspan='1'>content of the text node</td>
120
* <td valign='top' rowspan='1' colspan='1'>null</td>
123
* <p>See also the <a href='http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113'>Document Object Model (DOM) Level 2 Core Specification</a>.
125
public interface Node {
128
* The node is an <code>Element</code>.
130
public static final short ELEMENT_NODE = 1;
132
* The node is an <code>Attr</code>.
134
public static final short ATTRIBUTE_NODE = 2;
136
* The node is a <code>Text</code> node.
138
public static final short TEXT_NODE = 3;
140
* The node is a <code>CDATASection</code>.
142
public static final short CDATA_SECTION_NODE = 4;
144
* The node is an <code>EntityReference</code>.
146
public static final short ENTITY_REFERENCE_NODE = 5;
148
* The node is an <code>Entity</code>.
150
public static final short ENTITY_NODE = 6;
152
* The node is a <code>ProcessingInstruction</code>.
154
public static final short PROCESSING_INSTRUCTION_NODE = 7;
156
* The node is a <code>Comment</code>.
158
public static final short COMMENT_NODE = 8;
160
* The node is a <code>Document</code>.
162
public static final short DOCUMENT_NODE = 9;
164
* The node is a <code>DocumentType</code>.
166
public static final short DOCUMENT_TYPE_NODE = 10;
168
* The node is a <code>DocumentFragment</code>.
170
public static final short DOCUMENT_FRAGMENT_NODE = 11;
172
* The node is a <code>Notation</code>.
174
public static final short NOTATION_NODE = 12;
177
* The name of this node, depending on its type; see the table above.
179
public String getNodeName();
182
* The value of this node, depending on its type; see the table above.
183
* When it is defined to be <code>null</code>, setting it has no effect.
184
* @exception DOMException
185
* NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
186
* @exception DOMException
187
* DOMSTRING_SIZE_ERR: Raised when it would return more characters than
188
* fit in a <code>DOMString</code> variable on the implementation
191
public String getNodeValue()
194
* The value of this node, depending on its type; see the table above.
195
* When it is defined to be <code>null</code>, setting it has no effect.
196
* @exception DOMException
197
* NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
198
* @exception DOMException
199
* DOMSTRING_SIZE_ERR: Raised when it would return more characters than
200
* fit in a <code>DOMString</code> variable on the implementation
203
public void setNodeValue(String nodeValue)
207
* A code representing the type of the underlying object, as defined above.
209
public short getNodeType();
212
* The parent of this node. All nodes, except <code>Attr</code>,
213
* <code>Document</code>, <code>DocumentFragment</code>,
214
* <code>Entity</code>, and <code>Notation</code> may have a parent.
215
* However, if a node has just been created and not yet added to the
216
* tree, or if it has been removed from the tree, this is
219
public Node getParentNode();
222
* A <code>NodeList</code> that contains all children of this node. If
223
* there are no children, this is a <code>NodeList</code> containing no
226
public NodeList getChildNodes();
229
* The first child of this node. If there is no such node, this returns
232
public Node getFirstChild();
235
* The last child of this node. If there is no such node, this returns
238
public Node getLastChild();
241
* The node immediately preceding this node. If there is no such node,
242
* this returns <code>null</code>.
244
public Node getPreviousSibling();
247
* The node immediately following this node. If there is no such node,
248
* this returns <code>null</code>.
250
public Node getNextSibling();
253
* A <code>NamedNodeMap</code> containing the attributes of this node (if
254
* it is an <code>Element</code>) or <code>null</code> otherwise.
256
public NamedNodeMap getAttributes();
259
* The <code>Document</code> object associated with this node. This is
260
* also the <code>Document</code> object used to create new nodes. When
261
* this node is a <code>Document</code> or a <code>DocumentType</code>
262
* which is not used with any <code>Document</code> yet, this is
264
* @version DOM Level 2
266
public Document getOwnerDocument();
269
* Inserts the node <code>newChild</code> before the existing child node
270
* <code>refChild</code>. If <code>refChild</code> is <code>null</code>,
271
* insert <code>newChild</code> at the end of the list of children.
272
* <br>If <code>newChild</code> is a <code>DocumentFragment</code> object,
273
* all of its children are inserted, in the same order, before
274
* <code>refChild</code>. If the <code>newChild</code> is already in the
275
* tree, it is first removed.
276
* @param newChild The node to insert.
277
* @param refChild The reference node, i.e., the node before which the
278
* new node must be inserted.
279
* @return The node being inserted.
280
* @exception DOMException
281
* HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
282
* allow children of the type of the <code>newChild</code> node, or if
283
* the node to insert is one of this node's ancestors or this node
285
* <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created
286
* from a different document than the one that created this node.
287
* <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly or
288
* if the parent of the node being inserted is readonly.
289
* <br>NOT_FOUND_ERR: Raised if <code>refChild</code> is not a child of
292
public Node insertBefore(Node newChild,
297
* Replaces the child node <code>oldChild</code> with <code>newChild</code>
298
* in the list of children, and returns the <code>oldChild</code> node.
299
* <br>If <code>newChild</code> is a <code>DocumentFragment</code> object,
300
* <code>oldChild</code> is replaced by all of the
301
* <code>DocumentFragment</code> children, which are inserted in the
302
* same order. If the <code>newChild</code> is already in the tree, it
304
* @param newChild The new node to put in the child list.
305
* @param oldChild The node being replaced in the list.
306
* @return The node replaced.
307
* @exception DOMException
308
* HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
309
* allow children of the type of the <code>newChild</code> node, or if
310
* the node to put in is one of this node's ancestors or this node
312
* <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created
313
* from a different document than the one that created this node.
314
* <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node or the parent of
315
* the new node is readonly.
316
* <br>NOT_FOUND_ERR: Raised if <code>oldChild</code> is not a child of
319
public Node replaceChild(Node newChild,
324
* Removes the child node indicated by <code>oldChild</code> from the list
325
* of children, and returns it.
326
* @param oldChild The node being removed.
327
* @return The node removed.
328
* @exception DOMException
329
* NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
330
* <br>NOT_FOUND_ERR: Raised if <code>oldChild</code> is not a child of
333
public Node removeChild(Node oldChild)
337
* Adds the node <code>newChild</code> to the end of the list of children
338
* of this node. If the <code>newChild</code> is already in the tree, it
340
* @param newChild The node to add.If it is a
341
* <code>DocumentFragment</code> object, the entire contents of the
342
* document fragment are moved into the child list of this node
343
* @return The node added.
344
* @exception DOMException
345
* HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
346
* allow children of the type of the <code>newChild</code> node, or if
347
* the node to append is one of this node's ancestors or this node
349
* <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created
350
* from a different document than the one that created this node.
351
* <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly or
352
* if the previous parent of the node being inserted is readonly.
354
public Node appendChild(Node newChild)
358
* Returns whether this node has any children.
359
* @return <code>true</code> if this node has any children,
360
* <code>false</code> otherwise.
362
public boolean hasChildNodes();
365
* Returns a duplicate of this node, i.e., serves as a generic copy
366
* constructor for nodes. The duplicate node has no parent; (
367
* <code>parentNode</code> is <code>null</code>.).
368
* <br>Cloning an <code>Element</code> copies all attributes and their
369
* values, including those generated by the XML processor to represent
370
* defaulted attributes, but this method does not copy any text it
371
* contains unless it is a deep clone, since the text is contained in a
372
* child <code>Text</code> node. Cloning an <code>Attribute</code>
373
* directly, as opposed to be cloned as part of an <code>Element</code>
374
* cloning operation, returns a specified attribute (
375
* <code>specified</code> is <code>true</code>). Cloning any other type
376
* of node simply returns a copy of this node.
377
* <br>Note that cloning an immutable subtree results in a mutable copy,
378
* but the children of an <code>EntityReference</code> clone are readonly
379
* . In addition, clones of unspecified <code>Attr</code> nodes are
380
* specified. And, cloning <code>Document</code>,
381
* <code>DocumentType</code>, <code>Entity</code>, and
382
* <code>Notation</code> nodes is implementation dependent.
383
* @param deep If <code>true</code>, recursively clone the subtree under
384
* the specified node; if <code>false</code>, clone only the node
385
* itself (and its attributes, if it is an <code>Element</code>).
386
* @return The duplicate node.
388
public Node cloneNode(boolean deep);
391
* Puts all <code>Text</code> nodes in the full depth of the sub-tree
392
* underneath this <code>Node</code>, including attribute nodes, into a
393
* "normal" form where only structure (e.g., elements, comments,
394
* processing instructions, CDATA sections, and entity references)
395
* separates <code>Text</code> nodes, i.e., there are neither adjacent
396
* <code>Text</code> nodes nor empty <code>Text</code> nodes. This can
397
* be used to ensure that the DOM view of a document is the same as if
398
* it were saved and re-loaded, and is useful when operations (such as
399
* XPointer lookups) that depend on a particular document tree
400
* structure are to be used.In cases where the document contains
401
* <code>CDATASections</code>, the normalize operation alone may not be
402
* sufficient, since XPointers do not differentiate between
403
* <code>Text</code> nodes and <code>CDATASection</code> nodes.
404
* @version DOM Level 2
406
public void normalize();
409
* Tests whether the DOM implementation implements a specific feature and
410
* that feature is supported by this node.
411
* @param feature The name of the feature to test. This is the same name
412
* which can be passed to the method <code>hasFeature</code> on
413
* <code>DOMImplementation</code>.
414
* @param version This is the version number of the feature to test. In
415
* Level 2, version 1, this is the string "2.0". If the version is not
416
* specified, supporting any version of the feature will cause the
417
* method to return <code>true</code>.
418
* @return Returns <code>true</code> if the specified feature is
419
* supported on this node, <code>false</code> otherwise.
422
public boolean isSupported(String feature,
426
* The namespace URI of this node, or <code>null</code> if it is
428
* <br>This is not a computed value that is the result of a namespace
429
* lookup based on an examination of the namespace declarations in
430
* scope. It is merely the namespace URI given at creation time.
431
* <br>For nodes of any type other than <code>ELEMENT_NODE</code> and
432
* <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1
433
* method, such as <code>createElement</code> from the
434
* <code>Document</code> interface, this is always <code>null</code>.Per
435
* the Namespaces in XML Specification an attribute does not inherit
436
* its namespace from the element it is attached to. If an attribute is
437
* not explicitly given a namespace, it simply has no namespace.
440
public String getNamespaceURI();
443
* The namespace prefix of this node, or <code>null</code> if it is
445
* <br>Note that setting this attribute, when permitted, changes the
446
* <code>nodeName</code> attribute, which holds the qualified name, as
447
* well as the <code>tagName</code> and <code>name</code> attributes of
448
* the <code>Element</code> and <code>Attr</code> interfaces, when
450
* <br>Note also that changing the prefix of an attribute that is known to
451
* have a default value, does not make a new attribute with the default
452
* value and the original prefix appear, since the
453
* <code>namespaceURI</code> and <code>localName</code> do not change.
454
* <br>For nodes of any type other than <code>ELEMENT_NODE</code> and
455
* <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1
456
* method, such as <code>createElement</code> from the
457
* <code>Document</code> interface, this is always <code>null</code>.
458
* @exception DOMException
459
* INVALID_CHARACTER_ERR: Raised if the specified prefix contains an
460
* illegal character, per the XML 1.0 specification .
461
* <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
462
* <br>NAMESPACE_ERR: Raised if the specified <code>prefix</code> is
463
* malformed per the Namespaces in XML specification, if the
464
* <code>namespaceURI</code> of this node is <code>null</code>, if the
465
* specified prefix is "xml" and the <code>namespaceURI</code> of this
466
* node is different from "http://www.w3.org/XML/1998/namespace", if
467
* this node is an attribute and the specified prefix is "xmlns" and
468
* the <code>namespaceURI</code> of this node is different from "
469
* http://www.w3.org/2000/xmlns/", or if this node is an attribute and
470
* the <code>qualifiedName</code> of this node is "xmlns" .
473
public String getPrefix();
475
* The namespace prefix of this node, or <code>null</code> if it is
477
* <br>Note that setting this attribute, when permitted, changes the
478
* <code>nodeName</code> attribute, which holds the qualified name, as
479
* well as the <code>tagName</code> and <code>name</code> attributes of
480
* the <code>Element</code> and <code>Attr</code> interfaces, when
482
* <br>Note also that changing the prefix of an attribute that is known to
483
* have a default value, does not make a new attribute with the default
484
* value and the original prefix appear, since the
485
* <code>namespaceURI</code> and <code>localName</code> do not change.
486
* <br>For nodes of any type other than <code>ELEMENT_NODE</code> and
487
* <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1
488
* method, such as <code>createElement</code> from the
489
* <code>Document</code> interface, this is always <code>null</code>.
490
* @exception DOMException
491
* INVALID_CHARACTER_ERR: Raised if the specified prefix contains an
492
* illegal character, per the XML 1.0 specification .
493
* <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
494
* <br>NAMESPACE_ERR: Raised if the specified <code>prefix</code> is
495
* malformed per the Namespaces in XML specification, if the
496
* <code>namespaceURI</code> of this node is <code>null</code>, if the
497
* specified prefix is "xml" and the <code>namespaceURI</code> of this
498
* node is different from "http://www.w3.org/XML/1998/namespace", if
499
* this node is an attribute and the specified prefix is "xmlns" and
500
* the <code>namespaceURI</code> of this node is different from "
501
* http://www.w3.org/2000/xmlns/", or if this node is an attribute and
502
* the <code>qualifiedName</code> of this node is "xmlns" .
505
public void setPrefix(String prefix)
509
* Returns the local part of the qualified name of this node.
510
* <br>For nodes of any type other than <code>ELEMENT_NODE</code> and
511
* <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1
512
* method, such as <code>createElement</code> from the
513
* <code>Document</code> interface, this is always <code>null</code>.
516
public String getLocalName();
519
* Returns whether this node (if it is an element) has any attributes.
520
* @return <code>true</code> if this node has any attributes,
521
* <code>false</code> otherwise.
524
public boolean hasAttributes();