001/* 002 * Copyright (c) 2000 World Wide Web Consortium, 003 * (Massachusetts Institute of Technology, Institut National de 004 * Recherche en Informatique et en Automatique, Keio University). All 005 * Rights Reserved. This program is distributed under the W3C's Software 006 * Intellectual Property License. This program is distributed in the 007 * hope that it will be useful, but WITHOUT ANY WARRANTY; without even 008 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 009 * PURPOSE. 010 * See W3C License http://www.w3.org/Consortium/Legal/ for more details. 011 */ 012 013package org.w3c.dom; 014 015/** 016 * The <code>Document</code> interface represents the entire HTML or XML 017 * document. Conceptually, it is the root of the document tree, and provides 018 * the primary access to the document's data. 019 * <p>Since elements, text nodes, comments, processing instructions, etc. 020 * cannot exist outside the context of a <code>Document</code>, the 021 * <code>Document</code> interface also contains the factory methods needed 022 * to create these objects. The <code>Node</code> objects created have a 023 * <code>ownerDocument</code> attribute which associates them with the 024 * <code>Document</code> within whose context they were created. 025 * <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>. 026 */ 027public interface Document extends Node { 028 /** 029 * The Document Type Declaration (see <code>DocumentType</code>) 030 * associated with this document. For HTML documents as well as XML 031 * documents without a document type declaration this returns 032 * <code>null</code>. The DOM Level 2 does not support editing the 033 * Document Type Declaration. <code>docType</code> cannot be altered in 034 * any way, including through the use of methods inherited from the 035 * <code>Node</code> interface, such as <code>insertNode</code> or 036 * <code>removeNode</code>. 037 */ 038 public DocumentType getDoctype(); 039 040 /** 041 * The <code>DOMImplementation</code> object that handles this document. A 042 * DOM application may use objects from multiple implementations. 043 */ 044 public DOMImplementation getImplementation(); 045 046 /** 047 * This is a convenience attribute that allows direct access to the child 048 * node that is the root element of the document. For HTML documents, 049 * this is the element with the tagName "HTML". 050 */ 051 public Element getDocumentElement(); 052 053 /** 054 * Creates an element of the type specified. Note that the instance 055 * returned implements the <code>Element</code> interface, so attributes 056 * can be specified directly on the returned object. 057 * <br>In addition, if there are known attributes with default values, 058 * <code>Attr</code> nodes representing them are automatically created 059 * and attached to the element. 060 * <br>To create an element with a qualified name and namespace URI, use 061 * the <code>createElementNS</code> method. 062 * @param tagNameThe name of the element type to instantiate. For XML, 063 * this is case-sensitive. For HTML, the <code>tagName</code> 064 * parameter may be provided in any case, but it must be mapped to the 065 * canonical uppercase form by the DOM implementation. 066 * @return A new <code>Element</code> object with the 067 * <code>nodeName</code> attribute set to <code>tagName</code>, and 068 * <code>localName</code>, <code>prefix</code>, and 069 * <code>namespaceURI</code> set to <code>null</code>. 070 * @exception DOMException 071 * INVALID_CHARACTER_ERR: Raised if the specified name contains an 072 * illegal character. 073 */ 074 public Element createElement(String tagName) 075 throws DOMException; 076 077 /** 078 * Creates an empty <code>DocumentFragment</code> object. 079 * @return A new <code>DocumentFragment</code>. 080 */ 081 public DocumentFragment createDocumentFragment(); 082 083 /** 084 * Creates a <code>Text</code> node given the specified string. 085 * @param dataThe data for the node. 086 * @return The new <code>Text</code> object. 087 */ 088 public Text createTextNode(String data); 089 090 /** 091 * Creates a <code>Comment</code> node given the specified string. 092 * @param dataThe data for the node. 093 * @return The new <code>Comment</code> object. 094 */ 095 public Comment createComment(String data); 096 097 /** 098 * Creates a <code>CDATASection</code> node whose value is the specified 099 * string. 100 * @param dataThe data for the <code>CDATASection</code> contents. 101 * @return The new <code>CDATASection</code> object. 102 * @exception DOMException 103 * NOT_SUPPORTED_ERR: Raised if this document is an HTML document. 104 */ 105 public CDATASection createCDATASection(String data) 106 throws DOMException; 107 108 /** 109 * Creates a <code>ProcessingInstruction</code> node given the specified 110 * name and data strings. 111 * @param targetThe target part of the processing instruction. 112 * @param dataThe data for the node. 113 * @return The new <code>ProcessingInstruction</code> object. 114 * @exception DOMException 115 * INVALID_CHARACTER_ERR: Raised if the specified target contains an 116 * illegal character. 117 * <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document. 118 */ 119 public ProcessingInstruction createProcessingInstruction(String target, 120 String data) 121 throws DOMException; 122 123 /** 124 * Creates an <code>Attr</code> of the given name. Note that the 125 * <code>Attr</code> instance can then be set on an <code>Element</code> 126 * using the <code>setAttributeNode</code> method. 127 * <br>To create an attribute with a qualified name and namespace URI, use 128 * the <code>createAttributeNS</code> method. 129 * @param nameThe name of the attribute. 130 * @return A new <code>Attr</code> object with the <code>nodeName</code> 131 * attribute set to <code>name</code>, and <code>localName</code>, 132 * <code>prefix</code>, and <code>namespaceURI</code> set to 133 * <code>null</code>. The value of the attribute is the empty string. 134 * @exception DOMException 135 * INVALID_CHARACTER_ERR: Raised if the specified name contains an 136 * illegal character. 137 */ 138 public Attr createAttribute(String name) 139 throws DOMException; 140 141 /** 142 * Creates an <code>EntityReference</code> object. In addition, if the 143 * referenced entity is known, the child list of the 144 * <code>EntityReference</code> node is made the same as that of the 145 * corresponding <code>Entity</code> node.If any descendant of the 146 * <code>Entity</code> node has an unbound namespace prefix, the 147 * corresponding descendant of the created <code>EntityReference</code> 148 * node is also unbound; (its <code>namespaceURI</code> is 149 * <code>null</code>). The DOM Level 2 does not support any mechanism to 150 * resolve namespace prefixes. 151 * @param nameThe name of the entity to reference. 152 * @return The new <code>EntityReference</code> object. 153 * @exception DOMException 154 * INVALID_CHARACTER_ERR: Raised if the specified name contains an 155 * illegal character. 156 * <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document. 157 */ 158 public EntityReference createEntityReference(String name) 159 throws DOMException; 160 161 /** 162 * Returns a <code>NodeList</code> of all the <code>Elements</code> with a 163 * given tag name in the order in which they are encountered in a 164 * preorder traversal of the <code>Document</code> tree. 165 * @param tagnameThe name of the tag to match on. The special value "*" 166 * matches all tags. 167 * @return A new <code>NodeList</code> object containing all the matched 168 * <code>Elements</code>. 169 */ 170 public NodeList getElementsByTagName(String tagname); 171 172 /** 173 * Imports a node from another document to this document. The returned 174 * node has no parent; (<code>parentNode</code> is <code>null</code>). 175 * The source node is not altered or removed from the original document; 176 * this method creates a new copy of the source node. 177 * <br>For all nodes, importing a node creates a node object owned by the 178 * importing document, with attribute values identical to the source 179 * node's <code>nodeName</code> and <code>nodeType</code>, plus the 180 * attributes related to namespaces (<code>prefix</code>, 181 * <code>localName</code>, and <code>namespaceURI</code>). As in the 182 * <code>cloneNode</code> operation on a <code>Node</code>, the source 183 * node is not altered. 184 * <br>Additional information is copied as appropriate to the 185 * <code>nodeType</code>, attempting to mirror the behavior expected if 186 * a fragment of XML or HTML source was copied from one document to 187 * another, recognizing that the two documents may have different DTDs 188 * in the XML case. The following list describes the specifics for each 189 * type of node. 190 * <dl> 191 * <dt>ATTRIBUTE_NODE</dt> 192 * <dd>The <code>ownerElement</code> attribute 193 * is set to <code>null</code> and the <code>specified</code> flag is 194 * set to <code>true</code> on the generated <code>Attr</code>. The 195 * descendants of the source <code>Attr</code> are recursively imported 196 * and the resulting nodes reassembled to form the corresponding subtree. 197 * Note that the <code>deep</code> parameter has no effect on 198 * <code>Attr</code> nodes; they always carry their children with them 199 * when imported.</dd> 200 * <dt>DOCUMENT_FRAGMENT_NODE</dt> 201 * <dd>If the <code>deep</code> option 202 * was set to <code>true</code>, the descendants of the source element 203 * are recursively imported and the resulting nodes reassembled to form 204 * the corresponding subtree. Otherwise, this simply generates an empty 205 * <code>DocumentFragment</code>.</dd> 206 * <dt>DOCUMENT_NODE</dt> 207 * <dd><code>Document</code> 208 * nodes cannot be imported.</dd> 209 * <dt>DOCUMENT_TYPE_NODE</dt> 210 * <dd><code>DocumentType</code> 211 * nodes cannot be imported.</dd> 212 * <dt>ELEMENT_NODE</dt> 213 * <dd>Specified attribute nodes of the 214 * source element are imported, and the generated <code>Attr</code> 215 * nodes are attached to the generated <code>Element</code>. Default 216 * attributes are not copied, though if the document being imported into 217 * defines default attributes for this element name, those are assigned. 218 * If the <code>importNode</code> <code>deep</code> parameter was set to 219 * <code>true</code>, the descendants of the source element are 220 * recursively imported and the resulting nodes reassembled to form the 221 * corresponding subtree.</dd> 222 * <dt>ENTITY_NODE</dt> 223 * <dd><code>Entity</code> nodes can be 224 * imported, however in the current release of the DOM the 225 * <code>DocumentType</code> is readonly. Ability to add these imported 226 * nodes to a <code>DocumentType</code> will be considered for addition 227 * to a future release of the DOM.On import, the <code>publicId</code>, 228 * <code>systemId</code>, and <code>notationName</code> attributes are 229 * copied. If a <code>deep</code> import is requested, the descendants 230 * of the the source <code>Entity</code> are recursively imported and 231 * the resulting nodes reassembled to form the corresponding subtree.</dd> 232 * <dt> 233 * ENTITY_REFERENCE_NODE</dt> 234 * <dd>Only the <code>EntityReference</code> itself is 235 * copied, even if a <code>deep</code> import is requested, since the 236 * source and destination documents might have defined the entity 237 * differently. If the document being imported into provides a 238 * definition for this entity name, its value is assigned.</dd> 239 * <dt>NOTATION_NODE</dt> 240 * <dd> 241 * <code>Notation</code> nodes can be imported, however in the current 242 * release of the DOM the <code>DocumentType</code> is readonly. Ability 243 * to add these imported nodes to a <code>DocumentType</code> will be 244 * considered for addition to a future release of the DOM.On import, the 245 * <code>publicId</code> and <code>systemId</code> attributes are copied. 246 * Note that the <code>deep</code> parameter has no effect on 247 * <code>Notation</code> nodes since they never have any children.</dd> 248 * <dt> 249 * PROCESSING_INSTRUCTION_NODE</dt> 250 * <dd>The imported node copies its 251 * <code>target</code> and <code>data</code> values from those of the 252 * source node.</dd> 253 * <dt>TEXT_NODE, CDATA_SECTION_NODE, COMMENT_NODE</dt> 254 * <dd>These three 255 * types of nodes inheriting from <code>CharacterData</code> copy their 256 * <code>data</code> and <code>length</code> attributes from those of 257 * the source node.</dd> 258 * 259 * @param importedNodeThe node to import. 260 * @param deepIf <code>true</code>, recursively import the subtree under 261 * the specified node; if <code>false</code>, import only the node 262 * itself, as explained above. This has no effect on <code>Attr</code> 263 * , <code>EntityReference</code>, and <code>Notation</code> nodes. 264 * @return The imported node that belongs to this <code>Document</code>. 265 * @exception DOMException 266 * NOT_SUPPORTED_ERR: Raised if the type of node being imported is not 267 * supported. 268 * @since DOM Level 2 269 */ 270 public Node importNode(Node importedNode, 271 boolean deep) 272 throws DOMException; 273 274 /** 275 * Creates an element of the given qualified name and namespace URI. 276 * HTML-only DOM implementations do not need to implement this method. 277 * @param namespaceURIThe namespace URI of the element to create. 278 * @param qualifiedNameThe qualified name of the element type to 279 * instantiate. 280 * @return A new <code>Element</code> object with the following 281 * attributes:AttributeValue<code>Node.nodeName</code> 282 * <code>qualifiedName</code><code>Node.namespaceURI</code> 283 * <code>namespaceURI</code><code>Node.prefix</code>prefix, extracted 284 * from <code>qualifiedName</code>, or <code>null</code> if there is 285 * no prefix<code>Node.localName</code>local name, extracted from 286 * <code>qualifiedName</code><code>Element.tagName</code> 287 * <code>qualifiedName</code> 288 * @exception DOMException 289 * INVALID_CHARACTER_ERR: Raised if the specified qualified name 290 * contains an illegal character. 291 * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is 292 * malformed, if the <code>qualifiedName</code> has a prefix and the 293 * <code>namespaceURI</code> is <code>null</code>, or if the 294 * <code>qualifiedName</code> has a prefix that is "xml" and the 295 * <code>namespaceURI</code> is different from " 296 * http://www.w3.org/XML/1998/namespace" . 297 * @since DOM Level 2 298 */ 299 public Element createElementNS(String namespaceURI, 300 String qualifiedName) 301 throws DOMException; 302 303 /** 304 * Creates an attribute of the given qualified name and namespace URI. 305 * HTML-only DOM implementations do not need to implement this method. 306 * @param namespaceURIThe namespace URI of the attribute to create. 307 * @param qualifiedNameThe qualified name of the attribute to instantiate. 308 * @return A new <code>Attr</code> object with the following attributes: 309 * AttributeValue<code>Node.nodeName</code>qualifiedName 310 * <code>Node.namespaceURI</code><code>namespaceURI</code> 311 * <code>Node.prefix</code>prefix, extracted from 312 * <code>qualifiedName</code>, or <code>null</code> if there is no 313 * prefix<code>Node.localName</code>local name, extracted from 314 * <code>qualifiedName</code><code>Attr.name</code> 315 * <code>qualifiedName</code><code>Node.nodeValue</code>the empty 316 * string 317 * @exception DOMException 318 * INVALID_CHARACTER_ERR: Raised if the specified qualified name 319 * contains an illegal character. 320 * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is 321 * malformed, if the <code>qualifiedName</code> has a prefix and the 322 * <code>namespaceURI</code> is <code>null</code>, if the 323 * <code>qualifiedName</code> has a prefix that is "xml" and the 324 * <code>namespaceURI</code> is different from " 325 * http://www.w3.org/XML/1998/namespace", or if the 326 * <code>qualifiedName</code> is "xmlns" and the 327 * <code>namespaceURI</code> is different from " 328 * http://www.w3.org/2000/xmlns/". 329 * @since DOM Level 2 330 */ 331 public Attr createAttributeNS(String namespaceURI, 332 String qualifiedName) 333 throws DOMException; 334 335 /** 336 * Returns a <code>NodeList</code> of all the <code>Elements</code> with a 337 * given local name and namespace URI in the order in which they are 338 * encountered in a preorder traversal of the <code>Document</code> tree. 339 * @param namespaceURIThe namespace URI of the elements to match on. The 340 * special value "*" matches all namespaces. 341 * @param localNameThe local name of the elements to match on. The 342 * special value "*" matches all local names. 343 * @return A new <code>NodeList</code> object containing all the matched 344 * <code>Elements</code>. 345 * @since DOM Level 2 346 */ 347 public NodeList getElementsByTagNameNS(String namespaceURI, 348 String localName); 349 350 /** 351 * Returns the <code>Element</code> whose <code>ID</code> is given by 352 * <code>elementId</code>. If no such element exists, returns 353 * <code>null</code>. Behavior is not defined if more than one element 354 * has this <code>ID</code>. The DOM implementation must have 355 * information that says which attributes are of type ID. Attributes 356 * with the name "ID" are not of type ID unless so defined. 357 * Implementations that do not know whether attributes are of type ID or 358 * not are expected to return <code>null</code>. 359 * @param elementIdThe unique <code>id</code> value for an element. 360 * @return The matching element. 361 * @since DOM Level 2 362 */ 363 public Element getElementById(String elementId); 364 365}