001/*
002 * Copyright (c) 2000 World Wide Web Consortium,
003 * (Massachusetts Institute of Technology, Institut National de
004 * Recherche en Informatique et en Automatique, Keio University). All
005 * Rights Reserved. This program is distributed under the W3C's Software
006 * Intellectual Property License. This program is distributed in the
007 * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
008 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
009 * PURPOSE.
010 * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
011 */
012
013package org.w3c.dom;
014
015/**
016 * The <code>Node</code> interface is the primary datatype for the entire 
017 * Document Object Model. It represents a single node in the document tree. 
018 * While all objects implementing the <code>Node</code> interface expose 
019 * methods for dealing with children, not all objects implementing the 
020 * <code>Node</code> interface may have children. For example, 
021 * <code>Text</code> nodes may not have children, and adding children to 
022 * such nodes results in a <code>DOMException</code> being raised.
023 * <p>The attributes <code>nodeName</code>, <code>nodeValue</code> and 
024 * <code>attributes</code> are included as a mechanism to get at node 
025 * information without casting down to the specific derived interface. In 
026 * cases where there is no obvious mapping of these attributes for a 
027 * specific <code>nodeType</code> (e.g., <code>nodeValue</code> for an 
028 * <code>Element</code> or <code>attributes</code> for a <code>Comment</code>
029 * ), this returns <code>null</code>. Note that the specialized interfaces 
030 * may contain additional and more convenient mechanisms to get and set the 
031 * relevant information.
032 * <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>.
033 */
034public interface Node {
035    // NodeType
036    /**
037     * The node is an <code>Element</code>.
038     */
039    public static final short ELEMENT_NODE              = 1;
040    /**
041     * The node is an <code>Attr</code>.
042     */
043    public static final short ATTRIBUTE_NODE            = 2;
044    /**
045     * The node is a <code>Text</code> node.
046     */
047    public static final short TEXT_NODE                 = 3;
048    /**
049     * The node is a <code>CDATASection</code>.
050     */
051    public static final short CDATA_SECTION_NODE        = 4;
052    /**
053     * The node is an <code>EntityReference</code>.
054     */
055    public static final short ENTITY_REFERENCE_NODE     = 5;
056    /**
057     * The node is an <code>Entity</code>.
058     */
059    public static final short ENTITY_NODE               = 6;
060    /**
061     * The node is a <code>ProcessingInstruction</code>.
062     */
063    public static final short PROCESSING_INSTRUCTION_NODE = 7;
064    /**
065     * The node is a <code>Comment</code>.
066     */
067    public static final short COMMENT_NODE              = 8;
068    /**
069     * The node is a <code>Document</code>.
070     */
071    public static final short DOCUMENT_NODE             = 9;
072    /**
073     * The node is a <code>DocumentType</code>.
074     */
075    public static final short DOCUMENT_TYPE_NODE        = 10;
076    /**
077     * The node is a <code>DocumentFragment</code>.
078     */
079    public static final short DOCUMENT_FRAGMENT_NODE    = 11;
080    /**
081     * The node is a <code>Notation</code>.
082     */
083    public static final short NOTATION_NODE             = 12;
084
085    /**
086     * The name of this node, depending on its type; see the table above. 
087     */
088    public String getNodeName();
089
090    /**
091     * The value of this node, depending on its type; see the table above. 
092     * When it is defined to be <code>null</code>, setting it has no effect.
093     * @exception DOMException
094     *   NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
095     * @exception DOMException
096     *   DOMSTRING_SIZE_ERR: Raised when it would return more characters than 
097     *   fit in a <code>DOMString</code> variable on the implementation 
098     *   platform.
099     */
100    public String getNodeValue()
101                                 throws DOMException;
102    public void setNodeValue(String nodeValue)
103                                 throws DOMException;
104
105    /**
106     * A code representing the type of the underlying object, as defined above.
107     */
108    public short getNodeType();
109
110    /**
111     * The parent of this node. All nodes, except <code>Attr</code>, 
112     * <code>Document</code>, <code>DocumentFragment</code>, 
113     * <code>Entity</code>, and <code>Notation</code> may have a parent. 
114     * However, if a node has just been created and not yet added to the 
115     * tree, or if it has been removed from the tree, this is 
116     * <code>null</code>.
117     */
118    public Node getParentNode();
119
120    /**
121     * A <code>NodeList</code> that contains all children of this node. If 
122     * there are no children, this is a <code>NodeList</code> containing no 
123     * nodes.
124     */
125    public NodeList getChildNodes();
126
127    /**
128     * The first child of this node. If there is no such node, this returns 
129     * <code>null</code>.
130     */
131    public Node getFirstChild();
132
133    /**
134     * The last child of this node. If there is no such node, this returns 
135     * <code>null</code>.
136     */
137    public Node getLastChild();
138
139    /**
140     * The node immediately preceding this node. If there is no such node, 
141     * this returns <code>null</code>.
142     */
143    public Node getPreviousSibling();
144
145    /**
146     * The node immediately following this node. If there is no such node, 
147     * this returns <code>null</code>.
148     */
149    public Node getNextSibling();
150
151    /**
152     * A <code>NamedNodeMap</code> containing the attributes of this node (if 
153     * it is an <code>Element</code>) or <code>null</code> otherwise. 
154     */
155    public NamedNodeMap getAttributes();
156
157    /**
158     * The <code>Document</code> object associated with this node. This is 
159     * also the <code>Document</code> object used to create new nodes. When 
160     * this node is a <code>Document</code> or a <code>DocumentType</code> 
161     * which is not used with any <code>Document</code> yet, this is 
162     * <code>null</code>.
163     * @version DOM Level 2
164     */
165    public Document getOwnerDocument();
166
167    /**
168     * Inserts the node <code>newChild</code> before the existing child node 
169     * <code>refChild</code>. If <code>refChild</code> is <code>null</code>, 
170     * insert <code>newChild</code> at the end of the list of children.
171     * <br>If <code>newChild</code> is a <code>DocumentFragment</code> object, 
172     * all of its children are inserted, in the same order, before 
173     * <code>refChild</code>. If the <code>newChild</code> is already in the 
174     * tree, it is first removed.
175     * @param newChildThe node to insert.
176     * @param refChildThe reference node, i.e., the node before which the new 
177     *   node must be inserted.
178     * @return The node being inserted.
179     * @exception DOMException
180     *   HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not 
181     *   allow children of the type of the <code>newChild</code> node, or if 
182     *   the node to insert is one of this node's ancestors.
183     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created 
184     *   from a different document than the one that created this node.
185     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly or 
186     *   if the parent of the node being inserted is readonly.
187     *   <br>NOT_FOUND_ERR: Raised if <code>refChild</code> is not a child of 
188     *   this node.
189     */
190    public Node insertBefore(Node newChild, 
191                             Node refChild)
192                             throws DOMException;
193
194    /**
195     * Replaces the child node <code>oldChild</code> with <code>newChild</code>
196     *  in the list of children, and returns the <code>oldChild</code> node.
197     * <br>If <code>newChild</code> is a <code>DocumentFragment</code> object, 
198     * <code>oldChild</code> is replaced by all of the 
199     * <code>DocumentFragment</code> children, which are inserted in the 
200     * same order. If the <code>newChild</code> is already in the tree, it 
201     * is first removed.
202     * @param newChildThe new node to put in the child list.
203     * @param oldChildThe node being replaced in the list.
204     * @return The node replaced.
205     * @exception DOMException
206     *   HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not 
207     *   allow children of the type of the <code>newChild</code> node, or if 
208     *   the node to put in is one of this node's ancestors.
209     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created 
210     *   from a different document than the one that created this node.
211     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node or the parent of 
212     *   the new node is readonly.
213     *   <br>NOT_FOUND_ERR: Raised if <code>oldChild</code> is not a child of 
214     *   this node.
215     */
216    public Node replaceChild(Node newChild, 
217                             Node oldChild)
218                             throws DOMException;
219
220    /**
221     * Removes the child node indicated by <code>oldChild</code> from the list 
222     * of children, and returns it.
223     * @param oldChildThe node being removed.
224     * @return The node removed.
225     * @exception DOMException
226     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
227     *   <br>NOT_FOUND_ERR: Raised if <code>oldChild</code> is not a child of 
228     *   this node.
229     */
230    public Node removeChild(Node oldChild)
231                            throws DOMException;
232
233    /**
234     * Adds the node <code>newChild</code> to the end of the list of children 
235     * of this node. If the <code>newChild</code> is already in the tree, it 
236     * is first removed.
237     * @param newChildThe node to add.If it is a <code>DocumentFragment</code>
238     *    object, the entire contents of the document fragment are moved 
239     *   into the child list of this node
240     * @return The node added.
241     * @exception DOMException
242     *   HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not 
243     *   allow children of the type of the <code>newChild</code> node, or if 
244     *   the node to append is one of this node's ancestors.
245     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created 
246     *   from a different document than the one that created this node.
247     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
248     */
249    public Node appendChild(Node newChild)
250                            throws DOMException;
251
252    /**
253     * Returns whether this node has any children.
254     * @return  <code>true</code> if this node has any children, 
255     *   <code>false</code> otherwise.
256     */
257    public boolean hasChildNodes();
258
259    /**
260     * Returns a duplicate of this node, i.e., serves as a generic copy 
261     * constructor for nodes. The duplicate node has no parent; (
262     * <code>parentNode</code> is <code>null</code>.).
263     * <br>Cloning an <code>Element</code> copies all attributes and their 
264     * values, including those generated by the XML processor to represent 
265     * defaulted attributes, but this method does not copy any text it 
266     * contains unless it is a deep clone, since the text is contained in a 
267     * child <code>Text</code> node. Cloning an <code>Attribute</code> 
268     * directly, as opposed to be cloned as part of an <code>Element</code> 
269     * cloning operation, returns a specified attribute (
270     * <code>specified</code> is <code>true</code>). Cloning any other type 
271     * of node simply returns a copy of this node.
272     * <br>Note that cloning an immutable subtree results in a mutable copy, 
273     * but the children of an <code>EntityReference</code> clone are readonly
274     * . In addition, clones of unspecified <code>Attr</code> nodes are 
275     * specified. And, cloning <code>Document</code>, 
276     * <code>DocumentType</code>, <code>Entity</code>, and 
277     * <code>Notation</code> nodes is implementation dependent.
278     * @param deepIf <code>true</code>, recursively clone the subtree under 
279     *   the specified node; if <code>false</code>, clone only the node 
280     *   itself (and its attributes, if it is an <code>Element</code>). 
281     * @return The duplicate node.
282     */
283    public Node cloneNode(boolean deep);
284
285    /**
286     * Puts all <code>Text</code> nodes in the full depth of the sub-tree 
287     * underneath this <code>Node</code>, including attribute nodes, into a 
288     * "normal" form where only structure (e.g., elements, comments, 
289     * processing instructions, CDATA sections, and entity references) 
290     * separates <code>Text</code> nodes, i.e., there are neither adjacent 
291     * <code>Text</code> nodes nor empty <code>Text</code> nodes. This can 
292     * be used to ensure that the DOM view of a document is the same as if 
293     * it were saved and re-loaded, and is useful when operations (such as 
294     * XPointer  lookups) that depend on a particular document tree 
295     * structure are to be used.In cases where the document contains 
296     * <code>CDATASections</code>, the normalize operation alone may not be 
297     * sufficient, since XPointers do not differentiate between 
298     * <code>Text</code> nodes and <code>CDATASection</code> nodes.
299     * @version DOM Level 2
300     */
301    public void normalize();
302
303    /**
304     * Tests whether the DOM implementation implements a specific feature and 
305     * that feature is supported by this node.
306     * @param featureThe name of the feature to test. This is the same name 
307     *   which can be passed to the method <code>hasFeature</code> on 
308     *   <code>DOMImplementation</code>.
309     * @param versionThis is the version number of the feature to test. In 
310     *   Level 2, version 1, this is the string "2.0". If the version is not 
311     *   specified, supporting any version of the feature will cause the 
312     *   method to return <code>true</code>.
313     * @return Returns <code>true</code> if the specified feature is 
314     *   supported on this node, <code>false</code> otherwise.
315     * @since DOM Level 2
316     */
317    public boolean isSupported(String feature, 
318                               String version);
319
320    /**
321     * The namespace URI of this node, or <code>null</code> if it is 
322     * unspecified.
323     * <br>This is not a computed value that is the result of a namespace 
324     * lookup based on an examination of the namespace declarations in 
325     * scope. It is merely the namespace URI given at creation time.
326     * <br>For nodes of any type other than <code>ELEMENT_NODE</code> and 
327     * <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1 
328     * method, such as <code>createElement</code> from the 
329     * <code>Document</code> interface, this is always <code>null</code>.Per 
330     * the Namespaces in XML Specification  an attribute does not inherit 
331     * its namespace from the element it is attached to. If an attribute is 
332     * not explicitly given a namespace, it simply has no namespace.
333     * @since DOM Level 2
334     */
335    public String getNamespaceURI();
336
337    /**
338     * The namespace prefix of this node, or <code>null</code> if it is 
339     * unspecified.
340     * <br>Note that setting this attribute, when permitted, changes the 
341     * <code>nodeName</code> attribute, which holds the qualified name, as 
342     * well as the <code>tagName</code> and <code>name</code> attributes of 
343     * the <code>Element</code> and <code>Attr</code> interfaces, when 
344     * applicable.
345     * <br>Note also that changing the prefix of an attribute that is known to 
346     * have a default value, does not make a new attribute with the default 
347     * value and the original prefix appear, since the 
348     * <code>namespaceURI</code> and <code>localName</code> do not change.
349     * <br>For nodes of any type other than <code>ELEMENT_NODE</code> and 
350     * <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1 
351     * method, such as <code>createElement</code> from the 
352     * <code>Document</code> interface, this is always <code>null</code>.
353     * @exception DOMException
354     *   INVALID_CHARACTER_ERR: Raised if the specified prefix contains an 
355     *   illegal character.
356     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
357     *   <br>NAMESPACE_ERR: Raised if the specified <code>prefix</code> is 
358     *   malformed, if the <code>namespaceURI</code> of this node is 
359     *   <code>null</code>, if the specified prefix is "xml" and the 
360     *   <code>namespaceURI</code> of this node is different from "
361     *   http://www.w3.org/XML/1998/namespace", if this node is an attribute 
362     *   and the specified prefix is "xmlns" and the 
363     *   <code>namespaceURI</code> of this node is different from "
364     *   http://www.w3.org/2000/xmlns/", or if this node is an attribute and 
365     *   the <code>qualifiedName</code> of this node is "xmlns" .
366     * @since DOM Level 2
367     */
368    public String getPrefix();
369    public void setPrefix(String prefix)
370                               throws DOMException;
371
372    /**
373     * Returns the local part of the qualified name of this node.
374     * <br>For nodes of any type other than <code>ELEMENT_NODE</code> and 
375     * <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1 
376     * method, such as <code>createElement</code> from the 
377     * <code>Document</code> interface, this is always <code>null</code>.
378     * @since DOM Level 2
379     */
380    public String getLocalName();
381
382    /**
383     * Returns whether this node (if it is an element) has any attributes.
384     * @return <code>true</code> if this node has any attributes, 
385     *   <code>false</code> otherwise.
386     * @since DOM Level 2
387     */
388    public boolean hasAttributes();
389
390}