1 /*
2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3  *
4  * This code is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 only, as
6  * published by the Free Software Foundation.  Oracle designates this
7  * particular file as subject to the "Classpath" exception as provided
8  * by Oracle in the LICENSE file that accompanied this code.
9  *
10  * This code is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13  * version 2 for more details (a copy is included in the LICENSE file that
14  * accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License version
17  * 2 along with this work; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19  *
20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21  * or visit www.oracle.com if you need additional information or have any
22  * questions.
23  */
24 
25 /*
26  * This file is available under and governed by the GNU General Public
27  * License version 2 only, as published by the Free Software Foundation.
28  * However, the following notice accompanied the original version of this
29  * file and, per its terms, should not be removed:
30  *
31  * Copyright (c) 2004 World Wide Web Consortium,
32  *
33  * (Massachusetts Institute of Technology, European Research Consortium for
34  * Informatics and Mathematics, Keio University). All Rights Reserved. This
35  * work is distributed under the W3C(r) Software License [1] in the hope that
36  * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
37  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
38  *
39  * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
40  */
41 
42 package org.w3c.dom;
43 
44 /**
45  * The <code>Document</code> interface represents the entire HTML or XML
46  * document. Conceptually, it is the root of the document tree, and provides
47  * the primary access to the document's data.
48  * <p>Since elements, text nodes, comments, processing instructions, etc.
49  * cannot exist outside the context of a <code>Document</code>, the
50  * <code>Document</code> interface also contains the factory methods needed
51  * to create these objects. The <code>Node</code> objects created have a
52  * <code>ownerDocument</code> attribute which associates them with the
53  * <code>Document</code> within whose context they were created.
54  * <p>See also the <a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407'>Document Object Model (DOM) Level 3 Core Specification</a>.
55  */
56 public interface Document extends Node {
57     /**
58      * The Document Type Declaration (see <code>DocumentType</code>)
59      * associated with this document. For XML documents without a document
60      * type declaration this returns <code>null</code>. For HTML documents,
61      * a <code>DocumentType</code> object may be returned, independently of
62      * the presence or absence of document type declaration in the HTML
63      * document.
64      * <br>This provides direct access to the <code>DocumentType</code> node,
65      * child node of this <code>Document</code>. This node can be set at
66      * document creation time and later changed through the use of child
67      * nodes manipulation methods, such as <code>Node.insertBefore</code>,
68      * or <code>Node.replaceChild</code>. Note, however, that while some
69      * implementations may instantiate different types of
70      * <code>Document</code> objects supporting additional features than the
71      * "Core", such as "HTML" [<a href='http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109'>DOM Level 2 HTML</a>]
72      * , based on the <code>DocumentType</code> specified at creation time,
73      * changing it afterwards is very unlikely to result in a change of the
74      * features supported.
75      *
76      * @since 1.4, DOM Level 3
77      */
getDoctype()78     public DocumentType getDoctype();
79 
80     /**
81      * The <code>DOMImplementation</code> object that handles this document. A
82      * DOM application may use objects from multiple implementations.
83      */
getImplementation()84     public DOMImplementation getImplementation();
85 
86     /**
87      * This is a convenience attribute that allows direct access to the child
88      * node that is the document element of the document.
89      */
getDocumentElement()90     public Element getDocumentElement();
91 
92     /**
93      * Creates an element of the type specified. Note that the instance
94      * returned implements the <code>Element</code> interface, so attributes
95      * can be specified directly on the returned object.
96      * <br>In addition, if there are known attributes with default values,
97      * <code>Attr</code> nodes representing them are automatically created
98      * and attached to the element.
99      * <br>To create an element with a qualified name and namespace URI, use
100      * the <code>createElementNS</code> method.
101      * @param tagName The name of the element type to instantiate. For XML,
102      *   this is case-sensitive, otherwise it depends on the
103      *   case-sensitivity of the markup language in use. In that case, the
104      *   name is mapped to the canonical form of that markup by the DOM
105      *   implementation.
106      * @return A new <code>Element</code> object with the
107      *   <code>nodeName</code> attribute set to <code>tagName</code>, and
108      *   <code>localName</code>, <code>prefix</code>, and
109      *   <code>namespaceURI</code> set to <code>null</code>.
110      * @exception DOMException
111      *   INVALID_CHARACTER_ERR: Raised if the specified name is not an XML
112      *   name according to the XML version in use specified in the
113      *   <code>Document.xmlVersion</code> attribute.
114      */
createElement(String tagName)115     public Element createElement(String tagName)
116                                  throws DOMException;
117 
118     /**
119      * Creates an empty <code>DocumentFragment</code> object.
120      * @return A new <code>DocumentFragment</code>.
121      */
createDocumentFragment()122     public DocumentFragment createDocumentFragment();
123 
124     /**
125      * Creates a <code>Text</code> node given the specified string.
126      * @param data The data for the node.
127      * @return The new <code>Text</code> object.
128      */
createTextNode(String data)129     public Text createTextNode(String data);
130 
131     /**
132      * Creates a <code>Comment</code> node given the specified string.
133      * @param data The data for the node.
134      * @return The new <code>Comment</code> object.
135      */
createComment(String data)136     public Comment createComment(String data);
137 
138     /**
139      * Creates a <code>CDATASection</code> node whose value is the specified
140      * string.
141      * @param data The data for the <code>CDATASection</code> contents.
142      * @return The new <code>CDATASection</code> object.
143      * @exception DOMException
144      *   NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
145      */
createCDATASection(String data)146     public CDATASection createCDATASection(String data)
147                                            throws DOMException;
148 
149     /**
150      * Creates a <code>ProcessingInstruction</code> node given the specified
151      * name and data strings.
152      * @param target The target part of the processing instruction.Unlike
153      *   <code>Document.createElementNS</code> or
154      *   <code>Document.createAttributeNS</code>, no namespace well-formed
155      *   checking is done on the target name. Applications should invoke
156      *   <code>Document.normalizeDocument()</code> with the parameter "
157      *   namespaces" set to <code>true</code> in order to ensure that the
158      *   target name is namespace well-formed.
159      * @param data The data for the node.
160      * @return The new <code>ProcessingInstruction</code> object.
161      * @exception DOMException
162      *   INVALID_CHARACTER_ERR: Raised if the specified target is not an XML
163      *   name according to the XML version in use specified in the
164      *   <code>Document.xmlVersion</code> attribute.
165      *   <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
166      */
createProcessingInstruction(String target, String data)167     public ProcessingInstruction createProcessingInstruction(String target,
168                                                              String data)
169                                                              throws DOMException;
170 
171     /**
172      * Creates an <code>Attr</code> of the given name. Note that the
173      * <code>Attr</code> instance can then be set on an <code>Element</code>
174      * using the <code>setAttributeNode</code> method.
175      * <br>To create an attribute with a qualified name and namespace URI, use
176      * the <code>createAttributeNS</code> method.
177      * @param name The name of the attribute.
178      * @return A new <code>Attr</code> object with the <code>nodeName</code>
179      *   attribute set to <code>name</code>, and <code>localName</code>,
180      *   <code>prefix</code>, and <code>namespaceURI</code> set to
181      *   <code>null</code>. The value of the attribute is the empty string.
182      * @exception DOMException
183      *   INVALID_CHARACTER_ERR: Raised if the specified name is not an XML
184      *   name according to the XML version in use specified in the
185      *   <code>Document.xmlVersion</code> attribute.
186      */
createAttribute(String name)187     public Attr createAttribute(String name)
188                                 throws DOMException;
189 
190     /**
191      * Creates an <code>EntityReference</code> object. In addition, if the
192      * referenced entity is known, the child list of the
193      * <code>EntityReference</code> node is made the same as that of the
194      * corresponding <code>Entity</code> node.
195      * <p ><b>Note:</b> If any descendant of the <code>Entity</code> node has
196      * an unbound namespace prefix, the corresponding descendant of the
197      * created <code>EntityReference</code> node is also unbound; (its
198      * <code>namespaceURI</code> is <code>null</code>). The DOM Level 2 and
199      * 3 do not support any mechanism to resolve namespace prefixes in this
200      * case.
201      * @param name The name of the entity to reference.Unlike
202      *   <code>Document.createElementNS</code> or
203      *   <code>Document.createAttributeNS</code>, no namespace well-formed
204      *   checking is done on the entity name. Applications should invoke
205      *   <code>Document.normalizeDocument()</code> with the parameter "
206      *   namespaces" set to <code>true</code> in order to ensure that the
207      *   entity name is namespace well-formed.
208      * @return The new <code>EntityReference</code> object.
209      * @exception DOMException
210      *   INVALID_CHARACTER_ERR: Raised if the specified name is not an XML
211      *   name according to the XML version in use specified in the
212      *   <code>Document.xmlVersion</code> attribute.
213      *   <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
214      */
createEntityReference(String name)215     public EntityReference createEntityReference(String name)
216                                                  throws DOMException;
217 
218     /**
219      * Returns a <code>NodeList</code> of all the <code>Elements</code> in
220      * document order with a given tag name and are contained in the
221      * document.
222      * @param tagname  The name of the tag to match on. The special value "*"
223      *   matches all tags. For XML, the <code>tagname</code> parameter is
224      *   case-sensitive, otherwise it depends on the case-sensitivity of the
225      *   markup language in use.
226      * @return A new <code>NodeList</code> object containing all the matched
227      *   <code>Elements</code>.
228      */
getElementsByTagName(String tagname)229     public NodeList getElementsByTagName(String tagname);
230 
231     /**
232      * Imports a node from another document to this document, without altering
233      * or removing the source node from the original document; this method
234      * creates a new copy of the source node. The returned node has no
235      * parent; (<code>parentNode</code> is <code>null</code>).
236      * <br>For all nodes, importing a node creates a node object owned by the
237      * importing document, with attribute values identical to the source
238      * node's <code>nodeName</code> and <code>nodeType</code>, plus the
239      * attributes related to namespaces (<code>prefix</code>,
240      * <code>localName</code>, and <code>namespaceURI</code>). As in the
241      * <code>cloneNode</code> operation, the source node is not altered.
242      * User data associated to the imported node is not carried over.
243      * However, if any <code>UserDataHandlers</code> has been specified
244      * along with the associated data these handlers will be called with the
245      * appropriate parameters before this method returns.
246      * <br>Additional information is copied as appropriate to the
247      * <code>nodeType</code>, attempting to mirror the behavior expected if
248      * a fragment of XML or HTML source was copied from one document to
249      * another, recognizing that the two documents may have different DTDs
250      * in the XML case. The following list describes the specifics for each
251      * type of node.
252      * <dl>
253      * <dt>ATTRIBUTE_NODE</dt>
254      * <dd>The <code>ownerElement</code> attribute
255      * is set to <code>null</code> and the <code>specified</code> flag is
256      * set to <code>true</code> on the generated <code>Attr</code>. The
257      * descendants of the source <code>Attr</code> are recursively imported
258      * and the resulting nodes reassembled to form the corresponding subtree.
259      * Note that the <code>deep</code> parameter has no effect on
260      * <code>Attr</code> nodes; they always carry their children with them
261      * when imported.</dd>
262      * <dt>DOCUMENT_FRAGMENT_NODE</dt>
263      * <dd>If the <code>deep</code> option
264      * was set to <code>true</code>, the descendants of the source
265      * <code>DocumentFragment</code> are recursively imported and the
266      * resulting nodes reassembled under the imported
267      * <code>DocumentFragment</code> to form the corresponding subtree.
268      * Otherwise, this simply generates an empty
269      * <code>DocumentFragment</code>.</dd>
270      * <dt>DOCUMENT_NODE</dt>
271      * <dd><code>Document</code>
272      * nodes cannot be imported.</dd>
273      * <dt>DOCUMENT_TYPE_NODE</dt>
274      * <dd><code>DocumentType</code>
275      * nodes cannot be imported.</dd>
276      * <dt>ELEMENT_NODE</dt>
277      * <dd><em>Specified</em> attribute nodes of the source element are imported, and the generated
278      * <code>Attr</code> nodes are attached to the generated
279      * <code>Element</code>. Default attributes are <em>not</em> copied, though if the document being imported into defines default
280      * attributes for this element name, those are assigned. If the
281      * <code>importNode</code> <code>deep</code> parameter was set to
282      * <code>true</code>, the descendants of the source element are
283      * recursively imported and the resulting nodes reassembled to form the
284      * corresponding subtree.</dd>
285      * <dt>ENTITY_NODE</dt>
286      * <dd><code>Entity</code> nodes can be
287      * imported, however in the current release of the DOM the
288      * <code>DocumentType</code> is readonly. Ability to add these imported
289      * nodes to a <code>DocumentType</code> will be considered for addition
290      * to a future release of the DOM.On import, the <code>publicId</code>,
291      * <code>systemId</code>, and <code>notationName</code> attributes are
292      * copied. If a <code>deep</code> import is requested, the descendants
293      * of the the source <code>Entity</code> are recursively imported and
294      * the resulting nodes reassembled to form the corresponding subtree.</dd>
295      * <dt>
296      * ENTITY_REFERENCE_NODE</dt>
297      * <dd>Only the <code>EntityReference</code> itself is
298      * copied, even if a <code>deep</code> import is requested, since the
299      * source and destination documents might have defined the entity
300      * differently. If the document being imported into provides a
301      * definition for this entity name, its value is assigned.</dd>
302      * <dt>NOTATION_NODE</dt>
303      * <dd>
304      * <code>Notation</code> nodes can be imported, however in the current
305      * release of the DOM the <code>DocumentType</code> is readonly. Ability
306      * to add these imported nodes to a <code>DocumentType</code> will be
307      * considered for addition to a future release of the DOM.On import, the
308      * <code>publicId</code> and <code>systemId</code> attributes are copied.
309      * Note that the <code>deep</code> parameter has no effect on this type
310      * of nodes since they cannot have any children.</dd>
311      * <dt>
312      * PROCESSING_INSTRUCTION_NODE</dt>
313      * <dd>The imported node copies its
314      * <code>target</code> and <code>data</code> values from those of the
315      * source node.Note that the <code>deep</code> parameter has no effect
316      * on this type of nodes since they cannot have any children.</dd>
317      * <dt>TEXT_NODE,
318      * CDATA_SECTION_NODE, COMMENT_NODE</dt>
319      * <dd>These three types of nodes inheriting
320      * from <code>CharacterData</code> copy their <code>data</code> and
321      * <code>length</code> attributes from those of the source node.Note
322      * that the <code>deep</code> parameter has no effect on these types of
323      * nodes since they cannot have any children.</dd>
324      * </dl>
325      * @param importedNode The node to import.
326      * @param deep If <code>true</code>, recursively import the subtree under
327      *   the specified node; if <code>false</code>, import only the node
328      *   itself, as explained above. This has no effect on nodes that cannot
329      *   have any children, and on <code>Attr</code>, and
330      *   <code>EntityReference</code> nodes.
331      * @return The imported node that belongs to this <code>Document</code>.
332      * @exception DOMException
333      *   NOT_SUPPORTED_ERR: Raised if the type of node being imported is not
334      *   supported.
335      *   <br>INVALID_CHARACTER_ERR: Raised if one of the imported names is not
336      *   an XML name according to the XML version in use specified in the
337      *   <code>Document.xmlVersion</code> attribute. This may happen when
338      *   importing an XML 1.1 [<a href='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>] element
339      *   into an XML 1.0 document, for instance.
340      * @since 1.4, DOM Level 2
341      */
importNode(Node importedNode, boolean deep)342     public Node importNode(Node importedNode,
343                            boolean deep)
344                            throws DOMException;
345 
346     /**
347      * Creates an element of the given qualified name and namespace URI.
348      * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
349      * , applications must use the value <code>null</code> as the
350      * namespaceURI parameter for methods if they wish to have no namespace.
351      * @param namespaceURI The namespace URI of the element to create.
352      * @param qualifiedName The qualified name of the element type to
353      *   instantiate.
354      * @return A new <code>Element</code> object with the following
355      *   attributes:
356      * <table class="striped">
357      * <caption>Attributes of the {@code Element} object</caption>
358      * <thead>
359      * <tr>
360      * <th scope="col">Attribute</th>
361      * <th scope="col">Value</th>
362      * </tr>
363      * </thead>
364      * <tbody>
365      * <tr>
366      * <th scope="row"><code>Node.nodeName</code></th>
367      * <td>
368      *   <code>qualifiedName</code></td>
369      * </tr>
370      * <tr>
371      * <th scope="row"><code>Node.namespaceURI</code></th>
372      * <td>
373      *   <code>namespaceURI</code></td>
374      * </tr>
375      * <tr>
376      * <th scope="row"><code>Node.prefix</code></th>
377      * <td>prefix, extracted
378      *   from <code>qualifiedName</code>, or <code>null</code> if there is
379      *   no prefix</td>
380      * </tr>
381      * <tr>
382      * <th scope="row"><code>Node.localName</code></th>
383      * <td>local name, extracted from
384      *   <code>qualifiedName</code></td>
385      * </tr>
386      * <tr>
387      * <th scope="row"><code>Element.tagName</code></th>
388      * <td>
389      *   <code>qualifiedName</code></td>
390      * </tr>
391      * </tbody>
392      * </table>
393      * @exception DOMException
394      *   INVALID_CHARACTER_ERR: Raised if the specified
395      *   <code>qualifiedName</code> is not an XML name according to the XML
396      *   version in use specified in the <code>Document.xmlVersion</code>
397      *   attribute.
398      *   <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is a
399      *   malformed qualified name, if the <code>qualifiedName</code> has a
400      *   prefix and the <code>namespaceURI</code> is <code>null</code>, or
401      *   if the <code>qualifiedName</code> has a prefix that is "xml" and
402      *   the <code>namespaceURI</code> is different from "<a href='http://www.w3.org/XML/1998/namespace'>
403      *   http://www.w3.org/XML/1998/namespace</a>" [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
404      *   , or if the <code>qualifiedName</code> or its prefix is "xmlns" and
405      *   the <code>namespaceURI</code> is different from "<a href='http://www.w3.org/2000/xmlns/'>http://www.w3.org/2000/xmlns/</a>", or if the <code>namespaceURI</code> is "<a href='http://www.w3.org/2000/xmlns/'>http://www.w3.org/2000/xmlns/</a>" and neither the <code>qualifiedName</code> nor its prefix is "xmlns".
406      *   <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
407      *   support the <code>"XML"</code> feature, since namespaces were
408      *   defined by XML.
409      * @since 1.4, DOM Level 2
410      */
createElementNS(String namespaceURI, String qualifiedName)411     public Element createElementNS(String namespaceURI,
412                                    String qualifiedName)
413                                    throws DOMException;
414 
415     /**
416      * Creates an attribute of the given qualified name and namespace URI.
417      * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
418      * , applications must use the value <code>null</code> as the
419      * <code>namespaceURI</code> parameter for methods if they wish to have
420      * no namespace.
421      * @param namespaceURI The namespace URI of the attribute to create.
422      * @param qualifiedName The qualified name of the attribute to
423      *   instantiate.
424      * @return A new <code>Attr</code> object with the following attributes:
425      * <table class="striped">
426      * <caption>Attributes of the {@code Attr} object </caption>
427      * <thead>
428      * <tr>
429      * <th scope="col">
430      *   Attribute</th>
431      * <th scope="col">Value</th>
432      * </tr>
433      * </thead>
434      * <tbody>
435      * <tr>
436      * <th scope="row"><code>Node.nodeName</code></th>
437      * <td>qualifiedName</td>
438      * </tr>
439      * <tr>
440      * <th scope="row">
441      *   <code>Node.namespaceURI</code></th>
442      * <td><code>namespaceURI</code></td>
443      * </tr>
444      * <tr>
445      * <th scope="row">
446      *   <code>Node.prefix</code></th>
447      * <td>prefix, extracted from
448      *   <code>qualifiedName</code>, or <code>null</code> if there is no
449      *   prefix</td>
450      * </tr>
451      * <tr>
452      * <th scope="row"><code>Node.localName</code></th>
453      * <td>local name, extracted from
454      *   <code>qualifiedName</code></td>
455      * </tr>
456      * <tr>
457      * <th scope="row"><code>Attr.name</code></th>
458      * <td>
459      *   <code>qualifiedName</code></td>
460      * </tr>
461      * <tr>
462      * <th scope="row"><code>Node.nodeValue</code></th>
463      * <td>the empty
464      *   string</td>
465      * </tr>
466      * </tbody>
467      * </table>
468      * @exception DOMException
469      *   INVALID_CHARACTER_ERR: Raised if the specified
470      *   <code>qualifiedName</code> is not an XML name according to the XML
471      *   version in use specified in the <code>Document.xmlVersion</code>
472      *   attribute.
473      *   <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is a
474      *   malformed qualified name, if the <code>qualifiedName</code> has a
475      *   prefix and the <code>namespaceURI</code> is <code>null</code>, if
476      *   the <code>qualifiedName</code> has a prefix that is "xml" and the
477      *   <code>namespaceURI</code> is different from "<a href='http://www.w3.org/XML/1998/namespace'>
478      *   http://www.w3.org/XML/1998/namespace</a>", if the <code>qualifiedName</code> or its prefix is "xmlns" and the
479      *   <code>namespaceURI</code> is different from "<a href='http://www.w3.org/2000/xmlns/'>http://www.w3.org/2000/xmlns/</a>", or if the <code>namespaceURI</code> is "<a href='http://www.w3.org/2000/xmlns/'>http://www.w3.org/2000/xmlns/</a>" and neither the <code>qualifiedName</code> nor its prefix is "xmlns".
480      *   <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
481      *   support the <code>"XML"</code> feature, since namespaces were
482      *   defined by XML.
483      * @since 1.4, DOM Level 2
484      */
createAttributeNS(String namespaceURI, String qualifiedName)485     public Attr createAttributeNS(String namespaceURI,
486                                   String qualifiedName)
487                                   throws DOMException;
488 
489     /**
490      * Returns a <code>NodeList</code> of all the <code>Elements</code> with a
491      * given local name and namespace URI in document order.
492      * @param namespaceURI The namespace URI of the elements to match on. The
493      *   special value <code>"*"</code> matches all namespaces.
494      * @param localName The local name of the elements to match on. The
495      *   special value "*" matches all local names.
496      * @return A new <code>NodeList</code> object containing all the matched
497      *   <code>Elements</code>.
498      * @since 1.4, DOM Level 2
499      */
getElementsByTagNameNS(String namespaceURI, String localName)500     public NodeList getElementsByTagNameNS(String namespaceURI,
501                                            String localName);
502 
503     /**
504      * Returns the <code>Element</code> that has an ID attribute with the
505      * given value. If no such element exists, this returns <code>null</code>
506      * . If more than one element has an ID attribute with that value, what
507      * is returned is undefined.
508      * <br> The DOM implementation is expected to use the attribute
509      * <code>Attr.isId</code> to determine if an attribute is of type ID.
510      * <p ><b>Note:</b> Attributes with the name "ID" or "id" are not of type
511      * ID unless so defined.
512      * @param elementId The unique <code>id</code> value for an element.
513      * @return The matching element or <code>null</code> if there is none.
514      * @since 1.4, DOM Level 2
515      */
getElementById(String elementId)516     public Element getElementById(String elementId);
517 
518     /**
519      * An attribute specifying the encoding used for this document at the time
520      * of the parsing. This is <code>null</code> when it is not known, such
521      * as when the <code>Document</code> was created in memory.
522      * @since 1.5, DOM Level 3
523      */
getInputEncoding()524     public String getInputEncoding();
525 
526     /**
527      * An attribute specifying, as part of the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#NT-XMLDecl'>XML declaration</a>, the encoding of this document. This is <code>null</code> when
528      * unspecified or when it is not known, such as when the
529      * <code>Document</code> was created in memory.
530      * @since 1.5, DOM Level 3
531      */
getXmlEncoding()532     public String getXmlEncoding();
533 
534     /**
535      * An attribute specifying, as part of the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#NT-XMLDecl'>XML declaration</a>, whether this document is standalone. This is <code>false</code> when
536      * unspecified.
537      * <p ><b>Note:</b>  No verification is done on the value when setting
538      * this attribute. Applications should use
539      * <code>Document.normalizeDocument()</code> with the "validate"
540      * parameter to verify if the value matches the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#sec-rmd'>validity
541      * constraint for standalone document declaration</a> as defined in [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>].
542      * @since 1.5, DOM Level 3
543      */
getXmlStandalone()544     public boolean getXmlStandalone();
545     /**
546      * An attribute specifying, as part of the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#NT-XMLDecl'>XML declaration</a>, whether this document is standalone. This is <code>false</code> when
547      * unspecified.
548      * <p ><b>Note:</b>  No verification is done on the value when setting
549      * this attribute. Applications should use
550      * <code>Document.normalizeDocument()</code> with the "validate"
551      * parameter to verify if the value matches the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#sec-rmd'>validity
552      * constraint for standalone document declaration</a> as defined in [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>].
553      * @exception DOMException
554      *    NOT_SUPPORTED_ERR: Raised if this document does not support the
555      *   "XML" feature.
556      * @since 1.5, DOM Level 3
557      */
setXmlStandalone(boolean xmlStandalone)558     public void setXmlStandalone(boolean xmlStandalone)
559                                   throws DOMException;
560 
561     /**
562      *  An attribute specifying, as part of the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#NT-XMLDecl'>XML declaration</a>, the version number of this document. If there is no declaration and if
563      * this document supports the "XML" feature, the value is
564      * <code>"1.0"</code>. If this document does not support the "XML"
565      * feature, the value is always <code>null</code>. Changing this
566      * attribute will affect methods that check for invalid characters in
567      * XML names. Application should invoke
568      * <code>Document.normalizeDocument()</code> in order to check for
569      * invalid characters in the <code>Node</code>s that are already part of
570      * this <code>Document</code>.
571      * <br> DOM applications may use the
572      * <code>DOMImplementation.hasFeature(feature, version)</code> method
573      * with parameter values "XMLVersion" and "1.0" (respectively) to
574      * determine if an implementation supports [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>]. DOM
575      * applications may use the same method with parameter values
576      * "XMLVersion" and "1.1" (respectively) to determine if an
577      * implementation supports [<a href='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>]. In both
578      * cases, in order to support XML, an implementation must also support
579      * the "XML" feature defined in this specification. <code>Document</code>
580      *  objects supporting a version of the "XMLVersion" feature must not
581      * raise a <code>NOT_SUPPORTED_ERR</code> exception for the same version
582      * number when using <code>Document.xmlVersion</code>.
583      * @since 1.5, DOM Level 3
584      */
getXmlVersion()585     public String getXmlVersion();
586     /**
587      *  An attribute specifying, as part of the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#NT-XMLDecl'>XML declaration</a>, the version number of this document. If there is no declaration and if
588      * this document supports the "XML" feature, the value is
589      * <code>"1.0"</code>. If this document does not support the "XML"
590      * feature, the value is always <code>null</code>. Changing this
591      * attribute will affect methods that check for invalid characters in
592      * XML names. Application should invoke
593      * <code>Document.normalizeDocument()</code> in order to check for
594      * invalid characters in the <code>Node</code>s that are already part of
595      * this <code>Document</code>.
596      * <br> DOM applications may use the
597      * <code>DOMImplementation.hasFeature(feature, version)</code> method
598      * with parameter values "XMLVersion" and "1.0" (respectively) to
599      * determine if an implementation supports [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>]. DOM
600      * applications may use the same method with parameter values
601      * "XMLVersion" and "1.1" (respectively) to determine if an
602      * implementation supports [<a href='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>]. In both
603      * cases, in order to support XML, an implementation must also support
604      * the "XML" feature defined in this specification. <code>Document</code>
605      *  objects supporting a version of the "XMLVersion" feature must not
606      * raise a <code>NOT_SUPPORTED_ERR</code> exception for the same version
607      * number when using <code>Document.xmlVersion</code>.
608      * @exception DOMException
609      *    NOT_SUPPORTED_ERR: Raised if the version is set to a value that is
610      *   not supported by this <code>Document</code> or if this document
611      *   does not support the "XML" feature.
612      * @since 1.5, DOM Level 3
613      */
setXmlVersion(String xmlVersion)614     public void setXmlVersion(String xmlVersion)
615                                   throws DOMException;
616 
617     /**
618      * An attribute specifying whether error checking is enforced or not. When
619      * set to <code>false</code>, the implementation is free to not test
620      * every possible error case normally defined on DOM operations, and not
621      * raise any <code>DOMException</code> on DOM operations or report
622      * errors while using <code>Document.normalizeDocument()</code>. In case
623      * of error, the behavior is undefined. This attribute is
624      * <code>true</code> by default.
625      * @since 1.5, DOM Level 3
626      */
getStrictErrorChecking()627     public boolean getStrictErrorChecking();
628     /**
629      * An attribute specifying whether error checking is enforced or not. When
630      * set to <code>false</code>, the implementation is free to not test
631      * every possible error case normally defined on DOM operations, and not
632      * raise any <code>DOMException</code> on DOM operations or report
633      * errors while using <code>Document.normalizeDocument()</code>. In case
634      * of error, the behavior is undefined. This attribute is
635      * <code>true</code> by default.
636      * @since 1.5, DOM Level 3
637      */
setStrictErrorChecking(boolean strictErrorChecking)638     public void setStrictErrorChecking(boolean strictErrorChecking);
639 
640     /**
641      *  The location of the document or <code>null</code> if undefined or if
642      * the <code>Document</code> was created using
643      * <code>DOMImplementation.createDocument</code>. No lexical checking is
644      * performed when setting this attribute; this could result in a
645      * <code>null</code> value returned when using <code>Node.baseURI</code>
646      * .
647      * <br> Beware that when the <code>Document</code> supports the feature
648      * "HTML" [<a href='http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109'>DOM Level 2 HTML</a>]
649      * , the href attribute of the HTML BASE element takes precedence over
650      * this attribute when computing <code>Node.baseURI</code>.
651      * @since 1.5, DOM Level 3
652      */
getDocumentURI()653     public String getDocumentURI();
654     /**
655      *  The location of the document or <code>null</code> if undefined or if
656      * the <code>Document</code> was created using
657      * <code>DOMImplementation.createDocument</code>. No lexical checking is
658      * performed when setting this attribute; this could result in a
659      * <code>null</code> value returned when using <code>Node.baseURI</code>
660      * .
661      * <br> Beware that when the <code>Document</code> supports the feature
662      * "HTML" [<a href='http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109'>DOM Level 2 HTML</a>]
663      * , the href attribute of the HTML BASE element takes precedence over
664      * this attribute when computing <code>Node.baseURI</code>.
665      * @since 1.5, DOM Level 3
666      */
setDocumentURI(String documentURI)667     public void setDocumentURI(String documentURI);
668 
669     /**
670      *  Attempts to adopt a node from another document to this document. If
671      * supported, it changes the <code>ownerDocument</code> of the source
672      * node, its children, as well as the attached attribute nodes if there
673      * are any. If the source node has a parent it is first removed from the
674      * child list of its parent. This effectively allows moving a subtree
675      * from one document to another (unlike <code>importNode()</code> which
676      * create a copy of the source node instead of moving it). When it
677      * fails, applications should use <code>Document.importNode()</code>
678      * instead. Note that if the adopted node is already part of this
679      * document (i.e. the source and target document are the same), this
680      * method still has the effect of removing the source node from the
681      * child list of its parent, if any. The following list describes the
682      * specifics for each type of node.
683      * <dl>
684      * <dt>ATTRIBUTE_NODE</dt>
685      * <dd>The
686      * <code>ownerElement</code> attribute is set to <code>null</code> and
687      * the <code>specified</code> flag is set to <code>true</code> on the
688      * adopted <code>Attr</code>. The descendants of the source
689      * <code>Attr</code> are recursively adopted.</dd>
690      * <dt>DOCUMENT_FRAGMENT_NODE</dt>
691      * <dd>The
692      * descendants of the source node are recursively adopted.</dd>
693      * <dt>DOCUMENT_NODE</dt>
694      * <dd>
695      * <code>Document</code> nodes cannot be adopted.</dd>
696      * <dt>DOCUMENT_TYPE_NODE</dt>
697      * <dd>
698      * <code>DocumentType</code> nodes cannot be adopted.</dd>
699      * <dt>ELEMENT_NODE</dt>
700      * <dd><em>Specified</em> attribute nodes of the source element are adopted. Default attributes
701      * are discarded, though if the document being adopted into defines
702      * default attributes for this element name, those are assigned. The
703      * descendants of the source element are recursively adopted.</dd>
704      * <dt>ENTITY_NODE</dt>
705      * <dd>
706      * <code>Entity</code> nodes cannot be adopted.</dd>
707      * <dt>ENTITY_REFERENCE_NODE</dt>
708      * <dd>Only
709      * the <code>EntityReference</code> node itself is adopted, the
710      * descendants are discarded, since the source and destination documents
711      * might have defined the entity differently. If the document being
712      * imported into provides a definition for this entity name, its value
713      * is assigned.</dd>
714      * <dt>NOTATION_NODE</dt>
715      * <dd><code>Notation</code> nodes cannot be
716      * adopted.</dd>
717      * <dt>PROCESSING_INSTRUCTION_NODE, TEXT_NODE, CDATA_SECTION_NODE,
718      * COMMENT_NODE</dt>
719      * <dd>These nodes can all be adopted. No specifics.</dd>
720      * </dl>
721      * <p ><b>Note:</b>  Since it does not create new nodes unlike the
722      * <code>Document.importNode()</code> method, this method does not raise
723      * an <code>INVALID_CHARACTER_ERR</code> exception, and applications
724      * should use the <code>Document.normalizeDocument()</code> method to
725      * check if an imported name is not an XML name according to the XML
726      * version in use.
727      * @param source The node to move into this document.
728      * @return The adopted node, or <code>null</code> if this operation
729      *   fails, such as when the source node comes from a different
730      *   implementation.
731      * @exception DOMException
732      *   NOT_SUPPORTED_ERR: Raised if the source node is of type
733      *   <code>DOCUMENT</code>, <code>DOCUMENT_TYPE</code>.
734      *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised when the source node is
735      *   readonly.
736      * @since 1.5, DOM Level 3
737      */
adoptNode(Node source)738     public Node adoptNode(Node source)
739                           throws DOMException;
740 
741     /**
742      *  The configuration used when <code>Document.normalizeDocument()</code>
743      * is invoked.
744      * @since 1.5, DOM Level 3
745      */
getDomConfig()746     public DOMConfiguration getDomConfig();
747 
748     /**
749      *  This method acts as if the document was going through a save and load
750      * cycle, putting the document in a "normal" form. As a consequence,
751      * this method updates the replacement tree of
752      * <code>EntityReference</code> nodes and normalizes <code>Text</code>
753      * nodes, as defined in the method <code>Node.normalize()</code>.
754      * <br> Otherwise, the actual result depends on the features being set on
755      * the <code>Document.domConfig</code> object and governing what
756      * operations actually take place. Noticeably this method could also
757      * make the document namespace well-formed according to the algorithm
758      * described in , check the character normalization, remove the
759      * <code>CDATASection</code> nodes, etc. See
760      * <code>DOMConfiguration</code> for details.
761      * <pre>// Keep in the document
762      * the information defined // in the XML Information Set (Java example)
763      * DOMConfiguration docConfig = myDocument.getDomConfig();
764      * docConfig.setParameter("infoset", Boolean.TRUE);
765      * myDocument.normalizeDocument();</pre>
766      *
767      * <br>Mutation events, when supported, are generated to reflect the
768      * changes occurring on the document.
769      * <br> If errors occur during the invocation of this method, such as an
770      * attempt to update a read-only node or a <code>Node.nodeName</code>
771      * contains an invalid character according to the XML version in use,
772      * errors or warnings (<code>DOMError.SEVERITY_ERROR</code> or
773      * <code>DOMError.SEVERITY_WARNING</code>) will be reported using the
774      * <code>DOMErrorHandler</code> object associated with the "error-handler
775      * " parameter. Note this method might also report fatal errors (
776      * <code>DOMError.SEVERITY_FATAL_ERROR</code>) if an implementation
777      * cannot recover from an error.
778      * @since 1.5, DOM Level 3
779      */
normalizeDocument()780     public void normalizeDocument();
781 
782     /**
783      * Rename an existing node of type <code>ELEMENT_NODE</code> or
784      * <code>ATTRIBUTE_NODE</code>.
785      * <br>When possible this simply changes the name of the given node,
786      * otherwise this creates a new node with the specified name and
787      * replaces the existing node with the new node as described below.
788      * <br>If simply changing the name of the given node is not possible, the
789      * following operations are performed: a new node is created, any
790      * registered event listener is registered on the new node, any user
791      * data attached to the old node is removed from that node, the old node
792      * is removed from its parent if it has one, the children are moved to
793      * the new node, if the renamed node is an <code>Element</code> its
794      * attributes are moved to the new node, the new node is inserted at the
795      * position the old node used to have in its parent's child nodes list
796      * if it has one, the user data that was attached to the old node is
797      * attached to the new node.
798      * <br>When the node being renamed is an <code>Element</code> only the
799      * specified attributes are moved, default attributes originated from
800      * the DTD are updated according to the new element name. In addition,
801      * the implementation may update default attributes from other schemas.
802      * Applications should use <code>Document.normalizeDocument()</code> to
803      * guarantee these attributes are up-to-date.
804      * <br>When the node being renamed is an <code>Attr</code> that is
805      * attached to an <code>Element</code>, the node is first removed from
806      * the <code>Element</code> attributes map. Then, once renamed, either
807      * by modifying the existing node or creating a new one as described
808      * above, it is put back.
809      * <br>In addition,
810      * <ul>
811      * <li> a user data event <code>NODE_RENAMED</code> is fired,
812      * </li>
813      * <li>
814      * when the implementation supports the feature "MutationNameEvents",
815      * each mutation operation involved in this method fires the appropriate
816      * event, and in the end the event {
817      * <code>http://www.w3.org/2001/xml-events</code>,
818      * <code>DOMElementNameChanged</code>} or {
819      * <code>http://www.w3.org/2001/xml-events</code>,
820      * <code>DOMAttributeNameChanged</code>} is fired.
821      * </li>
822      * </ul>
823      * @param n The node to rename.
824      * @param namespaceURI The new namespace URI.
825      * @param qualifiedName The new qualified name.
826      * @return The renamed node. This is either the specified node or the new
827      *   node that was created to replace the specified node.
828      * @exception DOMException
829      *   NOT_SUPPORTED_ERR: Raised when the type of the specified node is
830      *   neither <code>ELEMENT_NODE</code> nor <code>ATTRIBUTE_NODE</code>,
831      *   or if the implementation does not support the renaming of the
832      *   document element.
833      *   <br>INVALID_CHARACTER_ERR: Raised if the new qualified name is not an
834      *   XML name according to the XML version in use specified in the
835      *   <code>Document.xmlVersion</code> attribute.
836      *   <br>WRONG_DOCUMENT_ERR: Raised when the specified node was created
837      *   from a different document than this document.
838      *   <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is a
839      *   malformed qualified name, if the <code>qualifiedName</code> has a
840      *   prefix and the <code>namespaceURI</code> is <code>null</code>, or
841      *   if the <code>qualifiedName</code> has a prefix that is "xml" and
842      *   the <code>namespaceURI</code> is different from "<a href='http://www.w3.org/XML/1998/namespace'>
843      *   http://www.w3.org/XML/1998/namespace</a>" [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
844      *   . Also raised, when the node being renamed is an attribute, if the
845      *   <code>qualifiedName</code>, or its prefix, is "xmlns" and the
846      *   <code>namespaceURI</code> is different from "<a href='http://www.w3.org/2000/xmlns/'>http://www.w3.org/2000/xmlns/</a>".
847      * @since 1.5, DOM Level 3
848      */
renameNode(Node n, String namespaceURI, String qualifiedName)849     public Node renameNode(Node n,
850                            String namespaceURI,
851                            String qualifiedName)
852                            throws DOMException;
853 
854 }
855