Path: blob/master/src/java.xml/share/classes/org/w3c/dom/Document.java
40948 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/*25* This file is available under and governed by the GNU General Public26* License version 2 only, as published by the Free Software Foundation.27* However, the following notice accompanied the original version of this28* file and, per its terms, should not be removed:29*30* Copyright (c) 2004 World Wide Web Consortium,31*32* (Massachusetts Institute of Technology, European Research Consortium for33* Informatics and Mathematics, Keio University). All Rights Reserved. This34* work is distributed under the W3C(r) Software License [1] in the hope that35* it will be useful, but WITHOUT ANY WARRANTY; without even the implied36* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.37*38* [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-2002123139*/4041package org.w3c.dom;4243/**44* The <code>Document</code> interface represents the entire HTML or XML45* document. Conceptually, it is the root of the document tree, and provides46* the primary access to the document's data.47* <p>Since elements, text nodes, comments, processing instructions, etc.48* cannot exist outside the context of a <code>Document</code>, the49* <code>Document</code> interface also contains the factory methods needed50* to create these objects. The <code>Node</code> objects created have a51* <code>ownerDocument</code> attribute which associates them with the52* <code>Document</code> within whose context they were created.53* <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>.54*/55public interface Document extends Node {56/**57* The Document Type Declaration (see <code>DocumentType</code>)58* associated with this document. For XML documents without a document59* type declaration this returns <code>null</code>. For HTML documents,60* a <code>DocumentType</code> object may be returned, independently of61* the presence or absence of document type declaration in the HTML62* document.63* <br>This provides direct access to the <code>DocumentType</code> node,64* child node of this <code>Document</code>. This node can be set at65* document creation time and later changed through the use of child66* nodes manipulation methods, such as <code>Node.insertBefore</code>,67* or <code>Node.replaceChild</code>. Note, however, that while some68* implementations may instantiate different types of69* <code>Document</code> objects supporting additional features than the70* "Core", such as "HTML" [<a href='http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109'>DOM Level 2 HTML</a>]71* , based on the <code>DocumentType</code> specified at creation time,72* changing it afterwards is very unlikely to result in a change of the73* features supported.74*75* @since 1.4, DOM Level 376*/77public DocumentType getDoctype();7879/**80* The <code>DOMImplementation</code> object that handles this document. A81* DOM application may use objects from multiple implementations.82*/83public DOMImplementation getImplementation();8485/**86* This is a convenience attribute that allows direct access to the child87* node that is the document element of the document.88*/89public Element getDocumentElement();9091/**92* Creates an element of the type specified. Note that the instance93* returned implements the <code>Element</code> interface, so attributes94* can be specified directly on the returned object.95* <br>In addition, if there are known attributes with default values,96* <code>Attr</code> nodes representing them are automatically created97* and attached to the element.98* <br>To create an element with a qualified name and namespace URI, use99* the <code>createElementNS</code> method.100* @param tagName The name of the element type to instantiate. For XML,101* this is case-sensitive, otherwise it depends on the102* case-sensitivity of the markup language in use. In that case, the103* name is mapped to the canonical form of that markup by the DOM104* implementation.105* @return A new <code>Element</code> object with the106* <code>nodeName</code> attribute set to <code>tagName</code>, and107* <code>localName</code>, <code>prefix</code>, and108* <code>namespaceURI</code> set to <code>null</code>.109* @exception DOMException110* INVALID_CHARACTER_ERR: Raised if the specified name is not an XML111* name according to the XML version in use specified in the112* <code>Document.xmlVersion</code> attribute.113*/114public Element createElement(String tagName)115throws DOMException;116117/**118* Creates an empty <code>DocumentFragment</code> object.119* @return A new <code>DocumentFragment</code>.120*/121public DocumentFragment createDocumentFragment();122123/**124* Creates a <code>Text</code> node given the specified string.125* @param data The data for the node.126* @return The new <code>Text</code> object.127*/128public Text createTextNode(String data);129130/**131* Creates a <code>Comment</code> node given the specified string.132* @param data The data for the node.133* @return The new <code>Comment</code> object.134*/135public Comment createComment(String data);136137/**138* Creates a <code>CDATASection</code> node whose value is the specified139* string.140* @param data The data for the <code>CDATASection</code> contents.141* @return The new <code>CDATASection</code> object.142* @exception DOMException143* NOT_SUPPORTED_ERR: Raised if this document is an HTML document.144*/145public CDATASection createCDATASection(String data)146throws DOMException;147148/**149* Creates a <code>ProcessingInstruction</code> node given the specified150* name and data strings.151* @param target The target part of the processing instruction.Unlike152* <code>Document.createElementNS</code> or153* <code>Document.createAttributeNS</code>, no namespace well-formed154* checking is done on the target name. Applications should invoke155* <code>Document.normalizeDocument()</code> with the parameter "156* namespaces" set to <code>true</code> in order to ensure that the157* target name is namespace well-formed.158* @param data The data for the node.159* @return The new <code>ProcessingInstruction</code> object.160* @exception DOMException161* INVALID_CHARACTER_ERR: Raised if the specified target is not an XML162* name according to the XML version in use specified in the163* <code>Document.xmlVersion</code> attribute.164* <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.165*/166public ProcessingInstruction createProcessingInstruction(String target,167String data)168throws DOMException;169170/**171* Creates an <code>Attr</code> of the given name. Note that the172* <code>Attr</code> instance can then be set on an <code>Element</code>173* using the <code>setAttributeNode</code> method.174* <br>To create an attribute with a qualified name and namespace URI, use175* the <code>createAttributeNS</code> method.176* @param name The name of the attribute.177* @return A new <code>Attr</code> object with the <code>nodeName</code>178* attribute set to <code>name</code>, and <code>localName</code>,179* <code>prefix</code>, and <code>namespaceURI</code> set to180* <code>null</code>. The value of the attribute is the empty string.181* @exception DOMException182* INVALID_CHARACTER_ERR: Raised if the specified name is not an XML183* name according to the XML version in use specified in the184* <code>Document.xmlVersion</code> attribute.185*/186public Attr createAttribute(String name)187throws DOMException;188189/**190* Creates an <code>EntityReference</code> object. In addition, if the191* referenced entity is known, the child list of the192* <code>EntityReference</code> node is made the same as that of the193* corresponding <code>Entity</code> node.194* <p ><b>Note:</b> If any descendant of the <code>Entity</code> node has195* an unbound namespace prefix, the corresponding descendant of the196* created <code>EntityReference</code> node is also unbound; (its197* <code>namespaceURI</code> is <code>null</code>). The DOM Level 2 and198* 3 do not support any mechanism to resolve namespace prefixes in this199* case.200* @param name The name of the entity to reference.Unlike201* <code>Document.createElementNS</code> or202* <code>Document.createAttributeNS</code>, no namespace well-formed203* checking is done on the entity name. Applications should invoke204* <code>Document.normalizeDocument()</code> with the parameter "205* namespaces" set to <code>true</code> in order to ensure that the206* entity name is namespace well-formed.207* @return The new <code>EntityReference</code> object.208* @exception DOMException209* INVALID_CHARACTER_ERR: Raised if the specified name is not an XML210* name according to the XML version in use specified in the211* <code>Document.xmlVersion</code> attribute.212* <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.213*/214public EntityReference createEntityReference(String name)215throws DOMException;216217/**218* Returns a <code>NodeList</code> of all the <code>Elements</code> in219* document order with a given tag name and are contained in the220* document.221* @param tagname The name of the tag to match on. The special value "*"222* matches all tags. For XML, the <code>tagname</code> parameter is223* case-sensitive, otherwise it depends on the case-sensitivity of the224* markup language in use.225* @return A new <code>NodeList</code> object containing all the matched226* <code>Elements</code>.227*/228public NodeList getElementsByTagName(String tagname);229230/**231* Imports a node from another document to this document, without altering232* or removing the source node from the original document; this method233* creates a new copy of the source node. The returned node has no234* parent; (<code>parentNode</code> is <code>null</code>).235* <br>For all nodes, importing a node creates a node object owned by the236* importing document, with attribute values identical to the source237* node's <code>nodeName</code> and <code>nodeType</code>, plus the238* attributes related to namespaces (<code>prefix</code>,239* <code>localName</code>, and <code>namespaceURI</code>). As in the240* <code>cloneNode</code> operation, the source node is not altered.241* User data associated to the imported node is not carried over.242* However, if any <code>UserDataHandlers</code> has been specified243* along with the associated data these handlers will be called with the244* appropriate parameters before this method returns.245* <br>Additional information is copied as appropriate to the246* <code>nodeType</code>, attempting to mirror the behavior expected if247* a fragment of XML or HTML source was copied from one document to248* another, recognizing that the two documents may have different DTDs249* in the XML case. The following list describes the specifics for each250* type of node.251* <dl>252* <dt>ATTRIBUTE_NODE</dt>253* <dd>The <code>ownerElement</code> attribute254* is set to <code>null</code> and the <code>specified</code> flag is255* set to <code>true</code> on the generated <code>Attr</code>. The256* descendants of the source <code>Attr</code> are recursively imported257* and the resulting nodes reassembled to form the corresponding subtree.258* Note that the <code>deep</code> parameter has no effect on259* <code>Attr</code> nodes; they always carry their children with them260* when imported.</dd>261* <dt>DOCUMENT_FRAGMENT_NODE</dt>262* <dd>If the <code>deep</code> option263* was set to <code>true</code>, the descendants of the source264* <code>DocumentFragment</code> are recursively imported and the265* resulting nodes reassembled under the imported266* <code>DocumentFragment</code> to form the corresponding subtree.267* Otherwise, this simply generates an empty268* <code>DocumentFragment</code>.</dd>269* <dt>DOCUMENT_NODE</dt>270* <dd><code>Document</code>271* nodes cannot be imported.</dd>272* <dt>DOCUMENT_TYPE_NODE</dt>273* <dd><code>DocumentType</code>274* nodes cannot be imported.</dd>275* <dt>ELEMENT_NODE</dt>276* <dd><em>Specified</em> attribute nodes of the source element are imported, and the generated277* <code>Attr</code> nodes are attached to the generated278* <code>Element</code>. Default attributes are <em>not</em> copied, though if the document being imported into defines default279* attributes for this element name, those are assigned. If the280* <code>importNode</code> <code>deep</code> parameter was set to281* <code>true</code>, the descendants of the source element are282* recursively imported and the resulting nodes reassembled to form the283* corresponding subtree.</dd>284* <dt>ENTITY_NODE</dt>285* <dd><code>Entity</code> nodes can be286* imported, however in the current release of the DOM the287* <code>DocumentType</code> is readonly. Ability to add these imported288* nodes to a <code>DocumentType</code> will be considered for addition289* to a future release of the DOM.On import, the <code>publicId</code>,290* <code>systemId</code>, and <code>notationName</code> attributes are291* copied. If a <code>deep</code> import is requested, the descendants292* of the the source <code>Entity</code> are recursively imported and293* the resulting nodes reassembled to form the corresponding subtree.</dd>294* <dt>295* ENTITY_REFERENCE_NODE</dt>296* <dd>Only the <code>EntityReference</code> itself is297* copied, even if a <code>deep</code> import is requested, since the298* source and destination documents might have defined the entity299* differently. If the document being imported into provides a300* definition for this entity name, its value is assigned.</dd>301* <dt>NOTATION_NODE</dt>302* <dd>303* <code>Notation</code> nodes can be imported, however in the current304* release of the DOM the <code>DocumentType</code> is readonly. Ability305* to add these imported nodes to a <code>DocumentType</code> will be306* considered for addition to a future release of the DOM.On import, the307* <code>publicId</code> and <code>systemId</code> attributes are copied.308* Note that the <code>deep</code> parameter has no effect on this type309* of nodes since they cannot have any children.</dd>310* <dt>311* PROCESSING_INSTRUCTION_NODE</dt>312* <dd>The imported node copies its313* <code>target</code> and <code>data</code> values from those of the314* source node.Note that the <code>deep</code> parameter has no effect315* on this type of nodes since they cannot have any children.</dd>316* <dt>TEXT_NODE,317* CDATA_SECTION_NODE, COMMENT_NODE</dt>318* <dd>These three types of nodes inheriting319* from <code>CharacterData</code> copy their <code>data</code> and320* <code>length</code> attributes from those of the source node.Note321* that the <code>deep</code> parameter has no effect on these types of322* nodes since they cannot have any children.</dd>323* </dl>324* @param importedNode The node to import.325* @param deep If <code>true</code>, recursively import the subtree under326* the specified node; if <code>false</code>, import only the node327* itself, as explained above. This has no effect on nodes that cannot328* have any children, and on <code>Attr</code>, and329* <code>EntityReference</code> nodes.330* @return The imported node that belongs to this <code>Document</code>.331* @exception DOMException332* NOT_SUPPORTED_ERR: Raised if the type of node being imported is not333* supported.334* <br>INVALID_CHARACTER_ERR: Raised if one of the imported names is not335* an XML name according to the XML version in use specified in the336* <code>Document.xmlVersion</code> attribute. This may happen when337* importing an XML 1.1 [<a href='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>] element338* into an XML 1.0 document, for instance.339* @since 1.4, DOM Level 2340*/341public Node importNode(Node importedNode,342boolean deep)343throws DOMException;344345/**346* Creates an element of the given qualified name and namespace URI.347* <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]348* , applications must use the value <code>null</code> as the349* namespaceURI parameter for methods if they wish to have no namespace.350* @param namespaceURI The namespace URI of the element to create.351* @param qualifiedName The qualified name of the element type to352* instantiate.353* @return A new <code>Element</code> object with the following354* attributes:355* <table class="striped">356* <caption>Attributes of the {@code Element} object</caption>357* <thead>358* <tr>359* <th scope="col">Attribute</th>360* <th scope="col">Value</th>361* </tr>362* </thead>363* <tbody>364* <tr>365* <th scope="row"><code>Node.nodeName</code></th>366* <td>367* <code>qualifiedName</code></td>368* </tr>369* <tr>370* <th scope="row"><code>Node.namespaceURI</code></th>371* <td>372* <code>namespaceURI</code></td>373* </tr>374* <tr>375* <th scope="row"><code>Node.prefix</code></th>376* <td>prefix, extracted377* from <code>qualifiedName</code>, or <code>null</code> if there is378* no prefix</td>379* </tr>380* <tr>381* <th scope="row"><code>Node.localName</code></th>382* <td>local name, extracted from383* <code>qualifiedName</code></td>384* </tr>385* <tr>386* <th scope="row"><code>Element.tagName</code></th>387* <td>388* <code>qualifiedName</code></td>389* </tr>390* </tbody>391* </table>392* @exception DOMException393* INVALID_CHARACTER_ERR: Raised if the specified394* <code>qualifiedName</code> is not an XML name according to the XML395* version in use specified in the <code>Document.xmlVersion</code>396* attribute.397* <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is a398* malformed qualified name, if the <code>qualifiedName</code> has a399* prefix and the <code>namespaceURI</code> is <code>null</code>, or400* if the <code>qualifiedName</code> has a prefix that is "xml" and401* the <code>namespaceURI</code> is different from "<a href='http://www.w3.org/XML/1998/namespace'>402* http://www.w3.org/XML/1998/namespace</a>" [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]403* , or if the <code>qualifiedName</code> or its prefix is "xmlns" and404* 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".405* <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not406* support the <code>"XML"</code> feature, since namespaces were407* defined by XML.408* @since 1.4, DOM Level 2409*/410public Element createElementNS(String namespaceURI,411String qualifiedName)412throws DOMException;413414/**415* Creates an attribute of the given qualified name and namespace URI.416* <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]417* , applications must use the value <code>null</code> as the418* <code>namespaceURI</code> parameter for methods if they wish to have419* no namespace.420* @param namespaceURI The namespace URI of the attribute to create.421* @param qualifiedName The qualified name of the attribute to422* instantiate.423* @return A new <code>Attr</code> object with the following attributes:424* <table class="striped">425* <caption>Attributes of the {@code Attr} object </caption>426* <thead>427* <tr>428* <th scope="col">429* Attribute</th>430* <th scope="col">Value</th>431* </tr>432* </thead>433* <tbody>434* <tr>435* <th scope="row"><code>Node.nodeName</code></th>436* <td>qualifiedName</td>437* </tr>438* <tr>439* <th scope="row">440* <code>Node.namespaceURI</code></th>441* <td><code>namespaceURI</code></td>442* </tr>443* <tr>444* <th scope="row">445* <code>Node.prefix</code></th>446* <td>prefix, extracted from447* <code>qualifiedName</code>, or <code>null</code> if there is no448* prefix</td>449* </tr>450* <tr>451* <th scope="row"><code>Node.localName</code></th>452* <td>local name, extracted from453* <code>qualifiedName</code></td>454* </tr>455* <tr>456* <th scope="row"><code>Attr.name</code></th>457* <td>458* <code>qualifiedName</code></td>459* </tr>460* <tr>461* <th scope="row"><code>Node.nodeValue</code></th>462* <td>the empty463* string</td>464* </tr>465* </tbody>466* </table>467* @exception DOMException468* INVALID_CHARACTER_ERR: Raised if the specified469* <code>qualifiedName</code> is not an XML name according to the XML470* version in use specified in the <code>Document.xmlVersion</code>471* attribute.472* <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is a473* malformed qualified name, if the <code>qualifiedName</code> has a474* prefix and the <code>namespaceURI</code> is <code>null</code>, if475* the <code>qualifiedName</code> has a prefix that is "xml" and the476* <code>namespaceURI</code> is different from "<a href='http://www.w3.org/XML/1998/namespace'>477* http://www.w3.org/XML/1998/namespace</a>", if the <code>qualifiedName</code> or its prefix is "xmlns" and the478* <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".479* <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not480* support the <code>"XML"</code> feature, since namespaces were481* defined by XML.482* @since 1.4, DOM Level 2483*/484public Attr createAttributeNS(String namespaceURI,485String qualifiedName)486throws DOMException;487488/**489* Returns a <code>NodeList</code> of all the <code>Elements</code> with a490* given local name and namespace URI in document order.491* @param namespaceURI The namespace URI of the elements to match on. The492* special value <code>"*"</code> matches all namespaces.493* @param localName The local name of the elements to match on. The494* special value "*" matches all local names.495* @return A new <code>NodeList</code> object containing all the matched496* <code>Elements</code>.497* @since 1.4, DOM Level 2498*/499public NodeList getElementsByTagNameNS(String namespaceURI,500String localName);501502/**503* Returns the <code>Element</code> that has an ID attribute with the504* given value. If no such element exists, this returns <code>null</code>505* . If more than one element has an ID attribute with that value, what506* is returned is undefined.507* <br> The DOM implementation is expected to use the attribute508* <code>Attr.isId</code> to determine if an attribute is of type ID.509* <p ><b>Note:</b> Attributes with the name "ID" or "id" are not of type510* ID unless so defined.511* @param elementId The unique <code>id</code> value for an element.512* @return The matching element or <code>null</code> if there is none.513* @since 1.4, DOM Level 2514*/515public Element getElementById(String elementId);516517/**518* An attribute specifying the encoding used for this document at the time519* of the parsing. This is <code>null</code> when it is not known, such520* as when the <code>Document</code> was created in memory.521* @since 1.5, DOM Level 3522*/523public String getInputEncoding();524525/**526* 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> when527* unspecified or when it is not known, such as when the528* <code>Document</code> was created in memory.529* @since 1.5, DOM Level 3530*/531public String getXmlEncoding();532533/**534* 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> when535* unspecified.536* <p ><b>Note:</b> No verification is done on the value when setting537* this attribute. Applications should use538* <code>Document.normalizeDocument()</code> with the "validate"539* parameter to verify if the value matches the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#sec-rmd'>validity540* constraint for standalone document declaration</a> as defined in [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>].541* @since 1.5, DOM Level 3542*/543public boolean getXmlStandalone();544/**545* 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> when546* unspecified.547* <p ><b>Note:</b> No verification is done on the value when setting548* this attribute. Applications should use549* <code>Document.normalizeDocument()</code> with the "validate"550* parameter to verify if the value matches the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#sec-rmd'>validity551* constraint for standalone document declaration</a> as defined in [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>].552* @exception DOMException553* NOT_SUPPORTED_ERR: Raised if this document does not support the554* "XML" feature.555* @since 1.5, DOM Level 3556*/557public void setXmlStandalone(boolean xmlStandalone)558throws DOMException;559560/**561* 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 if562* this document supports the "XML" feature, the value is563* <code>"1.0"</code>. If this document does not support the "XML"564* feature, the value is always <code>null</code>. Changing this565* attribute will affect methods that check for invalid characters in566* XML names. Application should invoke567* <code>Document.normalizeDocument()</code> in order to check for568* invalid characters in the <code>Node</code>s that are already part of569* this <code>Document</code>.570* <br> DOM applications may use the571* <code>DOMImplementation.hasFeature(feature, version)</code> method572* with parameter values "XMLVersion" and "1.0" (respectively) to573* determine if an implementation supports [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>]. DOM574* applications may use the same method with parameter values575* "XMLVersion" and "1.1" (respectively) to determine if an576* implementation supports [<a href='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>]. In both577* cases, in order to support XML, an implementation must also support578* the "XML" feature defined in this specification. <code>Document</code>579* objects supporting a version of the "XMLVersion" feature must not580* raise a <code>NOT_SUPPORTED_ERR</code> exception for the same version581* number when using <code>Document.xmlVersion</code>.582* @since 1.5, DOM Level 3583*/584public String getXmlVersion();585/**586* 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 if587* this document supports the "XML" feature, the value is588* <code>"1.0"</code>. If this document does not support the "XML"589* feature, the value is always <code>null</code>. Changing this590* attribute will affect methods that check for invalid characters in591* XML names. Application should invoke592* <code>Document.normalizeDocument()</code> in order to check for593* invalid characters in the <code>Node</code>s that are already part of594* this <code>Document</code>.595* <br> DOM applications may use the596* <code>DOMImplementation.hasFeature(feature, version)</code> method597* with parameter values "XMLVersion" and "1.0" (respectively) to598* determine if an implementation supports [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>]. DOM599* applications may use the same method with parameter values600* "XMLVersion" and "1.1" (respectively) to determine if an601* implementation supports [<a href='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>]. In both602* cases, in order to support XML, an implementation must also support603* the "XML" feature defined in this specification. <code>Document</code>604* objects supporting a version of the "XMLVersion" feature must not605* raise a <code>NOT_SUPPORTED_ERR</code> exception for the same version606* number when using <code>Document.xmlVersion</code>.607* @exception DOMException608* NOT_SUPPORTED_ERR: Raised if the version is set to a value that is609* not supported by this <code>Document</code> or if this document610* does not support the "XML" feature.611* @since 1.5, DOM Level 3612*/613public void setXmlVersion(String xmlVersion)614throws DOMException;615616/**617* An attribute specifying whether error checking is enforced or not. When618* set to <code>false</code>, the implementation is free to not test619* every possible error case normally defined on DOM operations, and not620* raise any <code>DOMException</code> on DOM operations or report621* errors while using <code>Document.normalizeDocument()</code>. In case622* of error, the behavior is undefined. This attribute is623* <code>true</code> by default.624* @since 1.5, DOM Level 3625*/626public boolean getStrictErrorChecking();627/**628* An attribute specifying whether error checking is enforced or not. When629* set to <code>false</code>, the implementation is free to not test630* every possible error case normally defined on DOM operations, and not631* raise any <code>DOMException</code> on DOM operations or report632* errors while using <code>Document.normalizeDocument()</code>. In case633* of error, the behavior is undefined. This attribute is634* <code>true</code> by default.635* @since 1.5, DOM Level 3636*/637public void setStrictErrorChecking(boolean strictErrorChecking);638639/**640* The location of the document or <code>null</code> if undefined or if641* the <code>Document</code> was created using642* <code>DOMImplementation.createDocument</code>. No lexical checking is643* performed when setting this attribute; this could result in a644* <code>null</code> value returned when using <code>Node.baseURI</code>645* .646* <br> Beware that when the <code>Document</code> supports the feature647* "HTML" [<a href='http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109'>DOM Level 2 HTML</a>]648* , the href attribute of the HTML BASE element takes precedence over649* this attribute when computing <code>Node.baseURI</code>.650* @since 1.5, DOM Level 3651*/652public String getDocumentURI();653/**654* The location of the document or <code>null</code> if undefined or if655* the <code>Document</code> was created using656* <code>DOMImplementation.createDocument</code>. No lexical checking is657* performed when setting this attribute; this could result in a658* <code>null</code> value returned when using <code>Node.baseURI</code>659* .660* <br> Beware that when the <code>Document</code> supports the feature661* "HTML" [<a href='http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109'>DOM Level 2 HTML</a>]662* , the href attribute of the HTML BASE element takes precedence over663* this attribute when computing <code>Node.baseURI</code>.664* @since 1.5, DOM Level 3665*/666public void setDocumentURI(String documentURI);667668/**669* Attempts to adopt a node from another document to this document. If670* supported, it changes the <code>ownerDocument</code> of the source671* node, its children, as well as the attached attribute nodes if there672* are any. If the source node has a parent it is first removed from the673* child list of its parent. This effectively allows moving a subtree674* from one document to another (unlike <code>importNode()</code> which675* create a copy of the source node instead of moving it). When it676* fails, applications should use <code>Document.importNode()</code>677* instead. Note that if the adopted node is already part of this678* document (i.e. the source and target document are the same), this679* method still has the effect of removing the source node from the680* child list of its parent, if any. The following list describes the681* specifics for each type of node.682* <dl>683* <dt>ATTRIBUTE_NODE</dt>684* <dd>The685* <code>ownerElement</code> attribute is set to <code>null</code> and686* the <code>specified</code> flag is set to <code>true</code> on the687* adopted <code>Attr</code>. The descendants of the source688* <code>Attr</code> are recursively adopted.</dd>689* <dt>DOCUMENT_FRAGMENT_NODE</dt>690* <dd>The691* descendants of the source node are recursively adopted.</dd>692* <dt>DOCUMENT_NODE</dt>693* <dd>694* <code>Document</code> nodes cannot be adopted.</dd>695* <dt>DOCUMENT_TYPE_NODE</dt>696* <dd>697* <code>DocumentType</code> nodes cannot be adopted.</dd>698* <dt>ELEMENT_NODE</dt>699* <dd><em>Specified</em> attribute nodes of the source element are adopted. Default attributes700* are discarded, though if the document being adopted into defines701* default attributes for this element name, those are assigned. The702* descendants of the source element are recursively adopted.</dd>703* <dt>ENTITY_NODE</dt>704* <dd>705* <code>Entity</code> nodes cannot be adopted.</dd>706* <dt>ENTITY_REFERENCE_NODE</dt>707* <dd>Only708* the <code>EntityReference</code> node itself is adopted, the709* descendants are discarded, since the source and destination documents710* might have defined the entity differently. If the document being711* imported into provides a definition for this entity name, its value712* is assigned.</dd>713* <dt>NOTATION_NODE</dt>714* <dd><code>Notation</code> nodes cannot be715* adopted.</dd>716* <dt>PROCESSING_INSTRUCTION_NODE, TEXT_NODE, CDATA_SECTION_NODE,717* COMMENT_NODE</dt>718* <dd>These nodes can all be adopted. No specifics.</dd>719* </dl>720* <p ><b>Note:</b> Since it does not create new nodes unlike the721* <code>Document.importNode()</code> method, this method does not raise722* an <code>INVALID_CHARACTER_ERR</code> exception, and applications723* should use the <code>Document.normalizeDocument()</code> method to724* check if an imported name is not an XML name according to the XML725* version in use.726* @param source The node to move into this document.727* @return The adopted node, or <code>null</code> if this operation728* fails, such as when the source node comes from a different729* implementation.730* @exception DOMException731* NOT_SUPPORTED_ERR: Raised if the source node is of type732* <code>DOCUMENT</code>, <code>DOCUMENT_TYPE</code>.733* <br>NO_MODIFICATION_ALLOWED_ERR: Raised when the source node is734* readonly.735* @since 1.5, DOM Level 3736*/737public Node adoptNode(Node source)738throws DOMException;739740/**741* The configuration used when <code>Document.normalizeDocument()</code>742* is invoked.743* @since 1.5, DOM Level 3744*/745public DOMConfiguration getDomConfig();746747/**748* This method acts as if the document was going through a save and load749* cycle, putting the document in a "normal" form. As a consequence,750* this method updates the replacement tree of751* <code>EntityReference</code> nodes and normalizes <code>Text</code>752* nodes, as defined in the method <code>Node.normalize()</code>.753* <br> Otherwise, the actual result depends on the features being set on754* the <code>Document.domConfig</code> object and governing what755* operations actually take place. Noticeably this method could also756* make the document namespace well-formed according to the algorithm757* described in , check the character normalization, remove the758* <code>CDATASection</code> nodes, etc. See759* <code>DOMConfiguration</code> for details.760* <pre>// Keep in the document761* the information defined // in the XML Information Set (Java example)762* DOMConfiguration docConfig = myDocument.getDomConfig();763* docConfig.setParameter("infoset", Boolean.TRUE);764* myDocument.normalizeDocument();</pre>765*766* <br>Mutation events, when supported, are generated to reflect the767* changes occurring on the document.768* <br> If errors occur during the invocation of this method, such as an769* attempt to update a read-only node or a <code>Node.nodeName</code>770* contains an invalid character according to the XML version in use,771* errors or warnings (<code>DOMError.SEVERITY_ERROR</code> or772* <code>DOMError.SEVERITY_WARNING</code>) will be reported using the773* <code>DOMErrorHandler</code> object associated with the "error-handler774* " parameter. Note this method might also report fatal errors (775* <code>DOMError.SEVERITY_FATAL_ERROR</code>) if an implementation776* cannot recover from an error.777* @since 1.5, DOM Level 3778*/779public void normalizeDocument();780781/**782* Rename an existing node of type <code>ELEMENT_NODE</code> or783* <code>ATTRIBUTE_NODE</code>.784* <br>When possible this simply changes the name of the given node,785* otherwise this creates a new node with the specified name and786* replaces the existing node with the new node as described below.787* <br>If simply changing the name of the given node is not possible, the788* following operations are performed: a new node is created, any789* registered event listener is registered on the new node, any user790* data attached to the old node is removed from that node, the old node791* is removed from its parent if it has one, the children are moved to792* the new node, if the renamed node is an <code>Element</code> its793* attributes are moved to the new node, the new node is inserted at the794* position the old node used to have in its parent's child nodes list795* if it has one, the user data that was attached to the old node is796* attached to the new node.797* <br>When the node being renamed is an <code>Element</code> only the798* specified attributes are moved, default attributes originated from799* the DTD are updated according to the new element name. In addition,800* the implementation may update default attributes from other schemas.801* Applications should use <code>Document.normalizeDocument()</code> to802* guarantee these attributes are up-to-date.803* <br>When the node being renamed is an <code>Attr</code> that is804* attached to an <code>Element</code>, the node is first removed from805* the <code>Element</code> attributes map. Then, once renamed, either806* by modifying the existing node or creating a new one as described807* above, it is put back.808* <br>In addition,809* <ul>810* <li> a user data event <code>NODE_RENAMED</code> is fired,811* </li>812* <li>813* when the implementation supports the feature "MutationNameEvents",814* each mutation operation involved in this method fires the appropriate815* event, and in the end the event {816* <code>http://www.w3.org/2001/xml-events</code>,817* <code>DOMElementNameChanged</code>} or {818* <code>http://www.w3.org/2001/xml-events</code>,819* <code>DOMAttributeNameChanged</code>} is fired.820* </li>821* </ul>822* @param n The node to rename.823* @param namespaceURI The new namespace URI.824* @param qualifiedName The new qualified name.825* @return The renamed node. This is either the specified node or the new826* node that was created to replace the specified node.827* @exception DOMException828* NOT_SUPPORTED_ERR: Raised when the type of the specified node is829* neither <code>ELEMENT_NODE</code> nor <code>ATTRIBUTE_NODE</code>,830* or if the implementation does not support the renaming of the831* document element.832* <br>INVALID_CHARACTER_ERR: Raised if the new qualified name is not an833* XML name according to the XML version in use specified in the834* <code>Document.xmlVersion</code> attribute.835* <br>WRONG_DOCUMENT_ERR: Raised when the specified node was created836* from a different document than this document.837* <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is a838* malformed qualified name, if the <code>qualifiedName</code> has a839* prefix and the <code>namespaceURI</code> is <code>null</code>, or840* if the <code>qualifiedName</code> has a prefix that is "xml" and841* the <code>namespaceURI</code> is different from "<a href='http://www.w3.org/XML/1998/namespace'>842* http://www.w3.org/XML/1998/namespace</a>" [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]843* . Also raised, when the node being renamed is an attribute, if the844* <code>qualifiedName</code>, or its prefix, is "xmlns" and the845* <code>namespaceURI</code> is different from "<a href='http://www.w3.org/2000/xmlns/'>http://www.w3.org/2000/xmlns/</a>".846* @since 1.5, DOM Level 3847*/848public Node renameNode(Node n,849String namespaceURI,850String qualifiedName)851throws DOMException;852853}854855856