1. /*
  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
  9. * PURPOSE.
  10. * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
  11. */
  12. package org.w3c.dom;
  13. /**
  14. * The <code>Node</code> interface is the primary datatype for the entire
  15. * Document Object Model. It represents a single node in the document tree.
  16. * While all objects implementing the <code>Node</code> interface expose
  17. * methods for dealing with children, not all objects implementing the
  18. * <code>Node</code> interface may have children. For example,
  19. * <code>Text</code> nodes may not have children, and adding children to
  20. * such nodes results in a <code>DOMException</code> being raised.
  21. * <p>The attributes <code>nodeName</code>, <code>nodeValue</code> and
  22. * <code>attributes</code> are included as a mechanism to get at node
  23. * information without casting down to the specific derived interface. In
  24. * cases where there is no obvious mapping of these attributes for a
  25. * specific <code>nodeType</code> (e.g., <code>nodeValue</code> for an
  26. * <code>Element</code> or <code>attributes</code> for a <code>Comment</code>
  27. * ), this returns <code>null</code>. Note that the specialized interfaces
  28. * may contain additional and more convenient mechanisms to get and set the
  29. * relevant information.
  30. * <p>The values of <code>nodeName</code>,
  31. * <code>nodeValue</code>, and <code>attributes</code> vary according to the
  32. * node type as follows:
  33. * <table border='1' summary="Describes interface, node name, node value, and attributes">
  34. * <tr>
  35. * <th>Interface</th>
  36. * <th>nodeName</th>
  37. * <th>nodeValue</th>
  38. * <th>attributes</th>
  39. * </tr>
  40. * <tr>
  41. * <td valign='top'>Attr</td>
  42. * <td valign='top'>name of
  43. * attribute</td>
  44. * <td valign='top'>value of attribute</td>
  45. * <td valign='top'>null</td>
  46. * </tr>
  47. * <tr>
  48. * <td valign='top'>CDATASection</td>
  49. * <td valign='top'><code>"#cdata-section"</code></td>
  50. * <td valign='top'>
  51. * content of the CDATA Section</td>
  52. * <td valign='top'>null</td>
  53. * </tr>
  54. * <tr>
  55. * <td valign='top'>Comment</td>
  56. * <td valign='top'><code>"#comment"</code></td>
  57. * <td valign='top'>content of
  58. * the comment</td>
  59. * <td valign='top'>null</td>
  60. * </tr>
  61. * <tr>
  62. * <td valign='top'>Document</td>
  63. * <td valign='top'><code>"#document"</code></td>
  64. * <td valign='top'>null</td>
  65. * <td valign='top'>null</td>
  66. * </tr>
  67. * <tr>
  68. * <td valign='top'>DocumentFragment</td>
  69. * <td valign='top'>
  70. * <code>"#document-fragment"</code></td>
  71. * <td valign='top'>null</td>
  72. * <td valign='top'>null</td>
  73. * </tr>
  74. * <tr>
  75. * <td valign='top'>DocumentType</td>
  76. * <td valign='top'>document type name</td>
  77. * <td valign='top'>
  78. * null</td>
  79. * <td valign='top'>null</td>
  80. * </tr>
  81. * <tr>
  82. * <td valign='top'>Element</td>
  83. * <td valign='top'>tag name</td>
  84. * <td valign='top'>null</td>
  85. * <td valign='top'>NamedNodeMap</td>
  86. * </tr>
  87. * <tr>
  88. * <td valign='top'>Entity</td>
  89. * <td valign='top'>entity name</td>
  90. * <td valign='top'>null</td>
  91. * <td valign='top'>null</td>
  92. * </tr>
  93. * <tr>
  94. * <td valign='top'>
  95. * EntityReference</td>
  96. * <td valign='top'>name of entity referenced</td>
  97. * <td valign='top'>null</td>
  98. * <td valign='top'>null</td>
  99. * </tr>
  100. * <tr>
  101. * <td valign='top'>Notation</td>
  102. * <td valign='top'>notation name</td>
  103. * <td valign='top'>null</td>
  104. * <td valign='top'>
  105. * null</td>
  106. * </tr>
  107. * <tr>
  108. * <td valign='top'>ProcessingInstruction</td>
  109. * <td valign='top'>target</td>
  110. * <td valign='top'>entire content excluding the target</td>
  111. * <td valign='top'>null</td>
  112. * </tr>
  113. * <tr>
  114. * <td valign='top'>Text</td>
  115. * <td valign='top'>
  116. * <code>"#text"</code></td>
  117. * <td valign='top'>content of the text node</td>
  118. * <td valign='top'>null</td>
  119. * </tr>
  120. * </table>
  121. * <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>.
  122. */
  123. public interface Node {
  124. // NodeType
  125. /**
  126. * The node is an <code>Element</code>.
  127. */
  128. public static final short ELEMENT_NODE = 1;
  129. /**
  130. * The node is an <code>Attr</code>.
  131. */
  132. public static final short ATTRIBUTE_NODE = 2;
  133. /**
  134. * The node is a <code>Text</code> node.
  135. */
  136. public static final short TEXT_NODE = 3;
  137. /**
  138. * The node is a <code>CDATASection</code>.
  139. */
  140. public static final short CDATA_SECTION_NODE = 4;
  141. /**
  142. * The node is an <code>EntityReference</code>.
  143. */
  144. public static final short ENTITY_REFERENCE_NODE = 5;
  145. /**
  146. * The node is an <code>Entity</code>.
  147. */
  148. public static final short ENTITY_NODE = 6;
  149. /**
  150. * The node is a <code>ProcessingInstruction</code>.
  151. */
  152. public static final short PROCESSING_INSTRUCTION_NODE = 7;
  153. /**
  154. * The node is a <code>Comment</code>.
  155. */
  156. public static final short COMMENT_NODE = 8;
  157. /**
  158. * The node is a <code>Document</code>.
  159. */
  160. public static final short DOCUMENT_NODE = 9;
  161. /**
  162. * The node is a <code>DocumentType</code>.
  163. */
  164. public static final short DOCUMENT_TYPE_NODE = 10;
  165. /**
  166. * The node is a <code>DocumentFragment</code>.
  167. */
  168. public static final short DOCUMENT_FRAGMENT_NODE = 11;
  169. /**
  170. * The node is a <code>Notation</code>.
  171. */
  172. public static final short NOTATION_NODE = 12;
  173. /**
  174. * The name of this node, depending on its type; see the table above.
  175. */
  176. public String getNodeName();
  177. /**
  178. * The value of this node, depending on its type; see the table above.
  179. * When it is defined to be <code>null</code>, setting it has no effect.
  180. * @exception DOMException
  181. * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
  182. * @exception DOMException
  183. * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
  184. * fit in a <code>DOMString</code> variable on the implementation
  185. * platform.
  186. */
  187. public String getNodeValue()
  188. throws DOMException;
  189. /**
  190. * The value of this node, depending on its type; see the table above.
  191. * When it is defined to be <code>null</code>, setting it has no effect.
  192. * @exception DOMException
  193. * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
  194. * @exception DOMException
  195. * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
  196. * fit in a <code>DOMString</code> variable on the implementation
  197. * platform.
  198. */
  199. public void setNodeValue(String nodeValue)
  200. throws DOMException;
  201. /**
  202. * A code representing the type of the underlying object, as defined above.
  203. */
  204. public short getNodeType();
  205. /**
  206. * The parent of this node. All nodes, except <code>Attr</code>,
  207. * <code>Document</code>, <code>DocumentFragment</code>,
  208. * <code>Entity</code>, and <code>Notation</code> may have a parent.
  209. * However, if a node has just been created and not yet added to the
  210. * tree, or if it has been removed from the tree, this is
  211. * <code>null</code>.
  212. */
  213. public Node getParentNode();
  214. /**
  215. * A <code>NodeList</code> that contains all children of this node. If
  216. * there are no children, this is a <code>NodeList</code> containing no
  217. * nodes.
  218. */
  219. public NodeList getChildNodes();
  220. /**
  221. * The first child of this node. If there is no such node, this returns
  222. * <code>null</code>.
  223. */
  224. public Node getFirstChild();
  225. /**
  226. * The last child of this node. If there is no such node, this returns
  227. * <code>null</code>.
  228. */
  229. public Node getLastChild();
  230. /**
  231. * The node immediately preceding this node. If there is no such node,
  232. * this returns <code>null</code>.
  233. */
  234. public Node getPreviousSibling();
  235. /**
  236. * The node immediately following this node. If there is no such node,
  237. * this returns <code>null</code>.
  238. */
  239. public Node getNextSibling();
  240. /**
  241. * A <code>NamedNodeMap</code> containing the attributes of this node (if
  242. * it is an <code>Element</code>) or <code>null</code> otherwise.
  243. */
  244. public NamedNodeMap getAttributes();
  245. /**
  246. * The <code>Document</code> object associated with this node. This is
  247. * also the <code>Document</code> object used to create new nodes. When
  248. * this node is a <code>Document</code> or a <code>DocumentType</code>
  249. * which is not used with any <code>Document</code> yet, this is
  250. * <code>null</code>.
  251. * @version DOM Level 2
  252. */
  253. public Document getOwnerDocument();
  254. /**
  255. * Inserts the node <code>newChild</code> before the existing child node
  256. * <code>refChild</code>. If <code>refChild</code> is <code>null</code>,
  257. * insert <code>newChild</code> at the end of the list of children.
  258. * <br>If <code>newChild</code> is a <code>DocumentFragment</code> object,
  259. * all of its children are inserted, in the same order, before
  260. * <code>refChild</code>. If the <code>newChild</code> is already in the
  261. * tree, it is first removed.
  262. * @param newChild The node to insert.
  263. * @param refChild The reference node, i.e., the node before which the
  264. * new node must be inserted.
  265. * @return The node being inserted.
  266. * @exception DOMException
  267. * HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
  268. * allow children of the type of the <code>newChild</code> node, or if
  269. * the node to insert is one of this node's ancestors or this node
  270. * itself.
  271. * <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created
  272. * from a different document than the one that created this node.
  273. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly or
  274. * if the parent of the node being inserted is readonly.
  275. * <br>NOT_FOUND_ERR: Raised if <code>refChild</code> is not a child of
  276. * this node.
  277. */
  278. public Node insertBefore(Node newChild,
  279. Node refChild)
  280. throws DOMException;
  281. /**
  282. * Replaces the child node <code>oldChild</code> with <code>newChild</code>
  283. * in the list of children, and returns the <code>oldChild</code> node.
  284. * <br>If <code>newChild</code> is a <code>DocumentFragment</code> object,
  285. * <code>oldChild</code> is replaced by all of the
  286. * <code>DocumentFragment</code> children, which are inserted in the
  287. * same order. If the <code>newChild</code> is already in the tree, it
  288. * is first removed.
  289. * @param newChild The new node to put in the child list.
  290. * @param oldChild The node being replaced in the list.
  291. * @return The node replaced.
  292. * @exception DOMException
  293. * HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
  294. * allow children of the type of the <code>newChild</code> node, or if
  295. * the node to put in is one of this node's ancestors or this node
  296. * itself.
  297. * <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created
  298. * from a different document than the one that created this node.
  299. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node or the parent of
  300. * the new node is readonly.
  301. * <br>NOT_FOUND_ERR: Raised if <code>oldChild</code> is not a child of
  302. * this node.
  303. */
  304. public Node replaceChild(Node newChild,
  305. Node oldChild)
  306. throws DOMException;
  307. /**
  308. * Removes the child node indicated by <code>oldChild</code> from the list
  309. * of children, and returns it.
  310. * @param oldChild The node being removed.
  311. * @return The node removed.
  312. * @exception DOMException
  313. * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  314. * <br>NOT_FOUND_ERR: Raised if <code>oldChild</code> is not a child of
  315. * this node.
  316. */
  317. public Node removeChild(Node oldChild)
  318. throws DOMException;
  319. /**
  320. * Adds the node <code>newChild</code> to the end of the list of children
  321. * of this node. If the <code>newChild</code> is already in the tree, it
  322. * is first removed.
  323. * @param newChild The node to add.If it is a
  324. * <code>DocumentFragment</code> object, the entire contents of the
  325. * document fragment are moved into the child list of this node
  326. * @return The node added.
  327. * @exception DOMException
  328. * HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
  329. * allow children of the type of the <code>newChild</code> node, or if
  330. * the node to append is one of this node's ancestors or this node
  331. * itself.
  332. * <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created
  333. * from a different document than the one that created this node.
  334. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly or
  335. * if the previous parent of the node being inserted is readonly.
  336. */
  337. public Node appendChild(Node newChild)
  338. throws DOMException;
  339. /**
  340. * Returns whether this node has any children.
  341. * @return <code>true</code> if this node has any children,
  342. * <code>false</code> otherwise.
  343. */
  344. public boolean hasChildNodes();
  345. /**
  346. * Returns a duplicate of this node, i.e., serves as a generic copy
  347. * constructor for nodes. The duplicate node has no parent; (
  348. * <code>parentNode</code> is <code>null</code>.).
  349. * <br>Cloning an <code>Element</code> copies all attributes and their
  350. * values, including those generated by the XML processor to represent
  351. * defaulted attributes, but this method does not copy any text it
  352. * contains unless it is a deep clone, since the text is contained in a
  353. * child <code>Text</code> node. Cloning an <code>Attribute</code>
  354. * directly, as opposed to be cloned as part of an <code>Element</code>
  355. * cloning operation, returns a specified attribute (
  356. * <code>specified</code> is <code>true</code>). Cloning any other type
  357. * of node simply returns a copy of this node.
  358. * <br>Note that cloning an immutable subtree results in a mutable copy,
  359. * but the children of an <code>EntityReference</code> clone are readonly
  360. * . In addition, clones of unspecified <code>Attr</code> nodes are
  361. * specified. And, cloning <code>Document</code>,
  362. * <code>DocumentType</code>, <code>Entity</code>, and
  363. * <code>Notation</code> nodes is implementation dependent.
  364. * @param deep If <code>true</code>, recursively clone the subtree under
  365. * the specified node; if <code>false</code>, clone only the node
  366. * itself (and its attributes, if it is an <code>Element</code>).
  367. * @return The duplicate node.
  368. */
  369. public Node cloneNode(boolean deep);
  370. /**
  371. * Puts all <code>Text</code> nodes in the full depth of the sub-tree
  372. * underneath this <code>Node</code>, including attribute nodes, into a
  373. * "normal" form where only structure (e.g., elements, comments,
  374. * processing instructions, CDATA sections, and entity references)
  375. * separates <code>Text</code> nodes, i.e., there are neither adjacent
  376. * <code>Text</code> nodes nor empty <code>Text</code> nodes. This can
  377. * be used to ensure that the DOM view of a document is the same as if
  378. * it were saved and re-loaded, and is useful when operations (such as
  379. * XPointer lookups) that depend on a particular document tree
  380. * structure are to be used.In cases where the document contains
  381. * <code>CDATASections</code>, the normalize operation alone may not be
  382. * sufficient, since XPointers do not differentiate between
  383. * <code>Text</code> nodes and <code>CDATASection</code> nodes.
  384. * @version DOM Level 2
  385. */
  386. public void normalize();
  387. /**
  388. * Tests whether the DOM implementation implements a specific feature and
  389. * that feature is supported by this node.
  390. * @param feature The name of the feature to test. This is the same name
  391. * which can be passed to the method <code>hasFeature</code> on
  392. * <code>DOMImplementation</code>.
  393. * @param version This is the version number of the feature to test. In
  394. * Level 2, version 1, this is the string "2.0". If the version is not
  395. * specified, supporting any version of the feature will cause the
  396. * method to return <code>true</code>.
  397. * @return Returns <code>true</code> if the specified feature is
  398. * supported on this node, <code>false</code> otherwise.
  399. * @since DOM Level 2
  400. */
  401. public boolean isSupported(String feature,
  402. String version);
  403. /**
  404. * The namespace URI of this node, or <code>null</code> if it is
  405. * unspecified.
  406. * <br>This is not a computed value that is the result of a namespace
  407. * lookup based on an examination of the namespace declarations in
  408. * scope. It is merely the namespace URI given at creation time.
  409. * <br>For nodes of any type other than <code>ELEMENT_NODE</code> and
  410. * <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1
  411. * method, such as <code>createElement</code> from the
  412. * <code>Document</code> interface, this is always <code>null</code>.Per
  413. * the Namespaces in XML Specification an attribute does not inherit
  414. * its namespace from the element it is attached to. If an attribute is
  415. * not explicitly given a namespace, it simply has no namespace.
  416. * @since DOM Level 2
  417. */
  418. public String getNamespaceURI();
  419. /**
  420. * The namespace prefix of this node, or <code>null</code> if it is
  421. * unspecified.
  422. * <br>Note that setting this attribute, when permitted, changes the
  423. * <code>nodeName</code> attribute, which holds the qualified name, as
  424. * well as the <code>tagName</code> and <code>name</code> attributes of
  425. * the <code>Element</code> and <code>Attr</code> interfaces, when
  426. * applicable.
  427. * <br>Note also that changing the prefix of an attribute that is known to
  428. * have a default value, does not make a new attribute with the default
  429. * value and the original prefix appear, since the
  430. * <code>namespaceURI</code> and <code>localName</code> do not change.
  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>.
  435. * @exception DOMException
  436. * INVALID_CHARACTER_ERR: Raised if the specified prefix contains an
  437. * illegal character, per the XML 1.0 specification .
  438. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  439. * <br>NAMESPACE_ERR: Raised if the specified <code>prefix</code> is
  440. * malformed per the Namespaces in XML specification, if the
  441. * <code>namespaceURI</code> of this node is <code>null</code>, if the
  442. * specified prefix is "xml" and the <code>namespaceURI</code> of this
  443. * node is different from "http://www.w3.org/XML/1998/namespace", if
  444. * this node is an attribute and the specified prefix is "xmlns" and
  445. * the <code>namespaceURI</code> of this node is different from "
  446. * http://www.w3.org/2000/xmlns/", or if this node is an attribute and
  447. * the <code>qualifiedName</code> of this node is "xmlns" .
  448. * @since DOM Level 2
  449. */
  450. public String getPrefix();
  451. /**
  452. * The namespace prefix of this node, or <code>null</code> if it is
  453. * unspecified.
  454. * <br>Note that setting this attribute, when permitted, changes the
  455. * <code>nodeName</code> attribute, which holds the qualified name, as
  456. * well as the <code>tagName</code> and <code>name</code> attributes of
  457. * the <code>Element</code> and <code>Attr</code> interfaces, when
  458. * applicable.
  459. * <br>Note also that changing the prefix of an attribute that is known to
  460. * have a default value, does not make a new attribute with the default
  461. * value and the original prefix appear, since the
  462. * <code>namespaceURI</code> and <code>localName</code> do not change.
  463. * <br>For nodes of any type other than <code>ELEMENT_NODE</code> and
  464. * <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1
  465. * method, such as <code>createElement</code> from the
  466. * <code>Document</code> interface, this is always <code>null</code>.
  467. * @exception DOMException
  468. * INVALID_CHARACTER_ERR: Raised if the specified prefix contains an
  469. * illegal character, per the XML 1.0 specification .
  470. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  471. * <br>NAMESPACE_ERR: Raised if the specified <code>prefix</code> is
  472. * malformed per the Namespaces in XML specification, if the
  473. * <code>namespaceURI</code> of this node is <code>null</code>, if the
  474. * specified prefix is "xml" and the <code>namespaceURI</code> of this
  475. * node is different from "http://www.w3.org/XML/1998/namespace", if
  476. * this node is an attribute and the specified prefix is "xmlns" and
  477. * the <code>namespaceURI</code> of this node is different from "
  478. * http://www.w3.org/2000/xmlns/", or if this node is an attribute and
  479. * the <code>qualifiedName</code> of this node is "xmlns" .
  480. * @since DOM Level 2
  481. */
  482. public void setPrefix(String prefix)
  483. throws DOMException;
  484. /**
  485. * Returns the local part of the qualified name of this node.
  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. * @since DOM Level 2
  491. */
  492. public String getLocalName();
  493. /**
  494. * Returns whether this node (if it is an element) has any attributes.
  495. * @return <code>true</code> if this node has any attributes,
  496. * <code>false</code> otherwise.
  497. * @since DOM Level 2
  498. */
  499. public boolean hasAttributes();
  500. }