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:
013: package 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: */
034: public 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() throws DOMException;
101:
102: public void setNodeValue(String nodeValue) throws DOMException;
103:
104: /**
105: * A code representing the type of the underlying object, as defined above.
106: */
107: public short getNodeType();
108:
109: /**
110: * The parent of this node. All nodes, except <code>Attr</code>,
111: * <code>Document</code>, <code>DocumentFragment</code>,
112: * <code>Entity</code>, and <code>Notation</code> may have a parent.
113: * However, if a node has just been created and not yet added to the
114: * tree, or if it has been removed from the tree, this is
115: * <code>null</code>.
116: */
117: public Node getParentNode();
118:
119: /**
120: * A <code>NodeList</code> that contains all children of this node. If
121: * there are no children, this is a <code>NodeList</code> containing no
122: * nodes.
123: */
124: public NodeList getChildNodes();
125:
126: /**
127: * The first child of this node. If there is no such node, this returns
128: * <code>null</code>.
129: */
130: public Node getFirstChild();
131:
132: /**
133: * The last child of this node. If there is no such node, this returns
134: * <code>null</code>.
135: */
136: public Node getLastChild();
137:
138: /**
139: * The node immediately preceding this node. If there is no such node,
140: * this returns <code>null</code>.
141: */
142: public Node getPreviousSibling();
143:
144: /**
145: * The node immediately following this node. If there is no such node,
146: * this returns <code>null</code>.
147: */
148: public Node getNextSibling();
149:
150: /**
151: * A <code>NamedNodeMap</code> containing the attributes of this node (if
152: * it is an <code>Element</code>) or <code>null</code> otherwise.
153: */
154: public NamedNodeMap getAttributes();
155:
156: /**
157: * The <code>Document</code> object associated with this node. This is
158: * also the <code>Document</code> object used to create new nodes. When
159: * this node is a <code>Document</code> or a <code>DocumentType</code>
160: * which is not used with any <code>Document</code> yet, this is
161: * <code>null</code>.
162: * @version DOM Level 2
163: */
164: public Document getOwnerDocument();
165:
166: /**
167: * Inserts the node <code>newChild</code> before the existing child node
168: * <code>refChild</code>. If <code>refChild</code> is <code>null</code>,
169: * insert <code>newChild</code> at the end of the list of children.
170: * <br>If <code>newChild</code> is a <code>DocumentFragment</code> object,
171: * all of its children are inserted, in the same order, before
172: * <code>refChild</code>. If the <code>newChild</code> is already in the
173: * tree, it is first removed.
174: * @param newChildThe node to insert.
175: * @param refChildThe reference node, i.e., the node before which the new
176: * node must be inserted.
177: * @return The node being inserted.
178: * @exception DOMException
179: * HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
180: * allow children of the type of the <code>newChild</code> node, or if
181: * the node to insert is one of this node's ancestors.
182: * <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created
183: * from a different document than the one that created this node.
184: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly or
185: * if the parent of the node being inserted is readonly.
186: * <br>NOT_FOUND_ERR: Raised if <code>refChild</code> is not a child of
187: * this node.
188: */
189: public Node insertBefore(Node newChild, Node refChild)
190: throws DOMException;
191:
192: /**
193: * Replaces the child node <code>oldChild</code> with <code>newChild</code>
194: * in the list of children, and returns the <code>oldChild</code> node.
195: * <br>If <code>newChild</code> is a <code>DocumentFragment</code> object,
196: * <code>oldChild</code> is replaced by all of the
197: * <code>DocumentFragment</code> children, which are inserted in the
198: * same order. If the <code>newChild</code> is already in the tree, it
199: * is first removed.
200: * @param newChildThe new node to put in the child list.
201: * @param oldChildThe node being replaced in the list.
202: * @return The node replaced.
203: * @exception DOMException
204: * HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
205: * allow children of the type of the <code>newChild</code> node, or if
206: * the node to put in is one of this node's ancestors.
207: * <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created
208: * from a different document than the one that created this node.
209: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node or the parent of
210: * the new node is readonly.
211: * <br>NOT_FOUND_ERR: Raised if <code>oldChild</code> is not a child of
212: * this node.
213: */
214: public Node replaceChild(Node newChild, Node oldChild)
215: throws DOMException;
216:
217: /**
218: * Removes the child node indicated by <code>oldChild</code> from the list
219: * of children, and returns it.
220: * @param oldChildThe node being removed.
221: * @return The node removed.
222: * @exception DOMException
223: * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
224: * <br>NOT_FOUND_ERR: Raised if <code>oldChild</code> is not a child of
225: * this node.
226: */
227: public Node removeChild(Node oldChild) throws DOMException;
228:
229: /**
230: * Adds the node <code>newChild</code> to the end of the list of children
231: * of this node. If the <code>newChild</code> is already in the tree, it
232: * is first removed.
233: * @param newChildThe node to add.If it is a <code>DocumentFragment</code>
234: * object, the entire contents of the document fragment are moved
235: * into the child list of this node
236: * @return The node added.
237: * @exception DOMException
238: * HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
239: * allow children of the type of the <code>newChild</code> node, or if
240: * the node to append is one of this node's ancestors.
241: * <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created
242: * from a different document than the one that created this node.
243: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
244: */
245: public Node appendChild(Node newChild) throws DOMException;
246:
247: /**
248: * Returns whether this node has any children.
249: * @return <code>true</code> if this node has any children,
250: * <code>false</code> otherwise.
251: */
252: public boolean hasChildNodes();
253:
254: /**
255: * Returns a duplicate of this node, i.e., serves as a generic copy
256: * constructor for nodes. The duplicate node has no parent; (
257: * <code>parentNode</code> is <code>null</code>.).
258: * <br>Cloning an <code>Element</code> copies all attributes and their
259: * values, including those generated by the XML processor to represent
260: * defaulted attributes, but this method does not copy any text it
261: * contains unless it is a deep clone, since the text is contained in a
262: * child <code>Text</code> node. Cloning an <code>Attribute</code>
263: * directly, as opposed to be cloned as part of an <code>Element</code>
264: * cloning operation, returns a specified attribute (
265: * <code>specified</code> is <code>true</code>). Cloning any other type
266: * of node simply returns a copy of this node.
267: * <br>Note that cloning an immutable subtree results in a mutable copy,
268: * but the children of an <code>EntityReference</code> clone are readonly
269: * . In addition, clones of unspecified <code>Attr</code> nodes are
270: * specified. And, cloning <code>Document</code>,
271: * <code>DocumentType</code>, <code>Entity</code>, and
272: * <code>Notation</code> nodes is implementation dependent.
273: * @param deepIf <code>true</code>, recursively clone the subtree under
274: * the specified node; if <code>false</code>, clone only the node
275: * itself (and its attributes, if it is an <code>Element</code>).
276: * @return The duplicate node.
277: */
278: public Node cloneNode(boolean deep);
279:
280: /**
281: * Puts all <code>Text</code> nodes in the full depth of the sub-tree
282: * underneath this <code>Node</code>, including attribute nodes, into a
283: * "normal" form where only structure (e.g., elements, comments,
284: * processing instructions, CDATA sections, and entity references)
285: * separates <code>Text</code> nodes, i.e., there are neither adjacent
286: * <code>Text</code> nodes nor empty <code>Text</code> nodes. This can
287: * be used to ensure that the DOM view of a document is the same as if
288: * it were saved and re-loaded, and is useful when operations (such as
289: * XPointer lookups) that depend on a particular document tree
290: * structure are to be used.In cases where the document contains
291: * <code>CDATASections</code>, the normalize operation alone may not be
292: * sufficient, since XPointers do not differentiate between
293: * <code>Text</code> nodes and <code>CDATASection</code> nodes.
294: * @version DOM Level 2
295: */
296: public void normalize();
297:
298: /**
299: * Tests whether the DOM implementation implements a specific feature and
300: * that feature is supported by this node.
301: * @param featureThe name of the feature to test. This is the same name
302: * which can be passed to the method <code>hasFeature</code> on
303: * <code>DOMImplementation</code>.
304: * @param versionThis is the version number of the feature to test. In
305: * Level 2, version 1, this is the string "2.0". If the version is not
306: * specified, supporting any version of the feature will cause the
307: * method to return <code>true</code>.
308: * @return Returns <code>true</code> if the specified feature is
309: * supported on this node, <code>false</code> otherwise.
310: * @since DOM Level 2
311: */
312: public boolean isSupported(String feature, String version);
313:
314: /**
315: * The namespace URI of this node, or <code>null</code> if it is
316: * unspecified.
317: * <br>This is not a computed value that is the result of a namespace
318: * lookup based on an examination of the namespace declarations in
319: * scope. It is merely the namespace URI given at creation time.
320: * <br>For nodes of any type other than <code>ELEMENT_NODE</code> and
321: * <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1
322: * method, such as <code>createElement</code> from the
323: * <code>Document</code> interface, this is always <code>null</code>.Per
324: * the Namespaces in XML Specification an attribute does not inherit
325: * its namespace from the element it is attached to. If an attribute is
326: * not explicitly given a namespace, it simply has no namespace.
327: * @since DOM Level 2
328: */
329: public String getNamespaceURI();
330:
331: /**
332: * The namespace prefix of this node, or <code>null</code> if it is
333: * unspecified.
334: * <br>Note that setting this attribute, when permitted, changes the
335: * <code>nodeName</code> attribute, which holds the qualified name, as
336: * well as the <code>tagName</code> and <code>name</code> attributes of
337: * the <code>Element</code> and <code>Attr</code> interfaces, when
338: * applicable.
339: * <br>Note also that changing the prefix of an attribute that is known to
340: * have a default value, does not make a new attribute with the default
341: * value and the original prefix appear, since the
342: * <code>namespaceURI</code> and <code>localName</code> do not change.
343: * <br>For nodes of any type other than <code>ELEMENT_NODE</code> and
344: * <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1
345: * method, such as <code>createElement</code> from the
346: * <code>Document</code> interface, this is always <code>null</code>.
347: * @exception DOMException
348: * INVALID_CHARACTER_ERR: Raised if the specified prefix contains an
349: * illegal character.
350: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
351: * <br>NAMESPACE_ERR: Raised if the specified <code>prefix</code> is
352: * malformed, if the <code>namespaceURI</code> of this node is
353: * <code>null</code>, if the specified prefix is "xml" and the
354: * <code>namespaceURI</code> of this node is different from "
355: * http://www.w3.org/XML/1998/namespace", if this node is an attribute
356: * and the specified prefix is "xmlns" and the
357: * <code>namespaceURI</code> of this node is different from "
358: * http://www.w3.org/2000/xmlns/", or if this node is an attribute and
359: * the <code>qualifiedName</code> of this node is "xmlns" .
360: * @since DOM Level 2
361: */
362: public String getPrefix();
363:
364: public void setPrefix(String prefix) throws DOMException;
365:
366: /**
367: * Returns the local part of the qualified name of this node.
368: * <br>For nodes of any type other than <code>ELEMENT_NODE</code> and
369: * <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1
370: * method, such as <code>createElement</code> from the
371: * <code>Document</code> interface, this is always <code>null</code>.
372: * @since DOM Level 2
373: */
374: public String getLocalName();
375:
376: /**
377: * Returns whether this node (if it is an element) has any attributes.
378: * @return <code>true</code> if this node has any attributes,
379: * <code>false</code> otherwise.
380: * @since DOM Level 2
381: */
382: public boolean hasAttributes();
383:
384: }
|