1. /*
  2. * Copyright (c) 2000 World Wide Web Consortium,
  3. * (Massachusetts Institute of Technology, Institut National de
  4. * Recherche en Informatique et en Automatique, Keio University). All
  5. * Rights Reserved. This program is distributed under the W3C's Software
  6. * Intellectual Property License. This program is distributed in the
  7. * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
  8. * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  9. * PURPOSE.
  10. * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
  11. */
  12. package org.w3c.dom;
  13. /**
  14. * The <code>Document</code> interface represents the entire HTML or XML
  15. * document. Conceptually, it is the root of the document tree, and provides
  16. * the primary access to the document's data.
  17. * <p>Since elements, text nodes, comments, processing instructions, etc.
  18. * cannot exist outside the context of a <code>Document</code>, the
  19. * <code>Document</code> interface also contains the factory methods needed
  20. * to create these objects. The <code>Node</code> objects created have a
  21. * <code>ownerDocument</code> attribute which associates them with the
  22. * <code>Document</code> within whose context they were created.
  23. * <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>.
  24. */
  25. public interface Document extends Node {
  26. /**
  27. * The Document Type Declaration (see <code>DocumentType</code>)
  28. * associated with this document. For HTML documents as well as XML
  29. * documents without a document type declaration this returns
  30. * <code>null</code>. The DOM Level 2 does not support editing the
  31. * Document Type Declaration. <code>docType</code> cannot be altered in
  32. * any way, including through the use of methods inherited from the
  33. * <code>Node</code> interface, such as <code>insertNode</code> or
  34. * <code>removeNode</code>.
  35. */
  36. public DocumentType getDoctype();
  37. /**
  38. * The <code>DOMImplementation</code> object that handles this document. A
  39. * DOM application may use objects from multiple implementations.
  40. */
  41. public DOMImplementation getImplementation();
  42. /**
  43. * This is a convenience attribute that allows direct access to the child
  44. * node that is the root element of the document. For HTML documents,
  45. * this is the element with the tagName "HTML".
  46. */
  47. public Element getDocumentElement();
  48. /**
  49. * Creates an element of the type specified. Note that the instance
  50. * returned implements the <code>Element</code> interface, so attributes
  51. * can be specified directly on the returned object.
  52. * <br>In addition, if there are known attributes with default values,
  53. * <code>Attr</code> nodes representing them are automatically created
  54. * and attached to the element.
  55. * <br>To create an element with a qualified name and namespace URI, use
  56. * the <code>createElementNS</code> method.
  57. * @param tagName The name of the element type to instantiate. For XML,
  58. * this is case-sensitive. For HTML, the <code>tagName</code>
  59. * parameter may be provided in any case, but it must be mapped to the
  60. * canonical uppercase form by the DOM implementation.
  61. * @return A new <code>Element</code> object with the
  62. * <code>nodeName</code> attribute set to <code>tagName</code>, and
  63. * <code>localName</code>, <code>prefix</code>, and
  64. * <code>namespaceURI</code> set to <code>null</code>.
  65. * @exception DOMException
  66. * INVALID_CHARACTER_ERR: Raised if the specified name contains an
  67. * illegal character.
  68. */
  69. public Element createElement(String tagName)
  70. throws DOMException;
  71. /**
  72. * Creates an empty <code>DocumentFragment</code> object.
  73. * @return A new <code>DocumentFragment</code>.
  74. */
  75. public DocumentFragment createDocumentFragment();
  76. /**
  77. * Creates a <code>Text</code> node given the specified string.
  78. * @param data The data for the node.
  79. * @return The new <code>Text</code> object.
  80. */
  81. public Text createTextNode(String data);
  82. /**
  83. * Creates a <code>Comment</code> node given the specified string.
  84. * @param data The data for the node.
  85. * @return The new <code>Comment</code> object.
  86. */
  87. public Comment createComment(String data);
  88. /**
  89. * Creates a <code>CDATASection</code> node whose value is the specified
  90. * string.
  91. * @param data The data for the <code>CDATASection</code> contents.
  92. * @return The new <code>CDATASection</code> object.
  93. * @exception DOMException
  94. * NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
  95. */
  96. public CDATASection createCDATASection(String data)
  97. throws DOMException;
  98. /**
  99. * Creates a <code>ProcessingInstruction</code> node given the specified
  100. * name and data strings.
  101. * @param target The target part of the processing instruction.
  102. * @param data The data for the node.
  103. * @return The new <code>ProcessingInstruction</code> object.
  104. * @exception DOMException
  105. * INVALID_CHARACTER_ERR: Raised if the specified target contains an
  106. * illegal character.
  107. * <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
  108. */
  109. public ProcessingInstruction createProcessingInstruction(String target,
  110. String data)
  111. throws DOMException;
  112. /**
  113. * Creates an <code>Attr</code> of the given name. Note that the
  114. * <code>Attr</code> instance can then be set on an <code>Element</code>
  115. * using the <code>setAttributeNode</code> method.
  116. * <br>To create an attribute with a qualified name and namespace URI, use
  117. * the <code>createAttributeNS</code> method.
  118. * @param name The name of the attribute.
  119. * @return A new <code>Attr</code> object with the <code>nodeName</code>
  120. * attribute set to <code>name</code>, and <code>localName</code>,
  121. * <code>prefix</code>, and <code>namespaceURI</code> set to
  122. * <code>null</code>. The value of the attribute is the empty string.
  123. * @exception DOMException
  124. * INVALID_CHARACTER_ERR: Raised if the specified name contains an
  125. * illegal character.
  126. */
  127. public Attr createAttribute(String name)
  128. throws DOMException;
  129. /**
  130. * Creates an <code>EntityReference</code> object. In addition, if the
  131. * referenced entity is known, the child list of the
  132. * <code>EntityReference</code> node is made the same as that of the
  133. * corresponding <code>Entity</code> node.If any descendant of the
  134. * <code>Entity</code> node has an unbound namespace prefix, the
  135. * corresponding descendant of the created <code>EntityReference</code>
  136. * node is also unbound; (its <code>namespaceURI</code> is
  137. * <code>null</code>). The DOM Level 2 does not support any mechanism to
  138. * resolve namespace prefixes.
  139. * @param name The name of the entity to reference.
  140. * @return The new <code>EntityReference</code> object.
  141. * @exception DOMException
  142. * INVALID_CHARACTER_ERR: Raised if the specified name contains an
  143. * illegal character.
  144. * <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
  145. */
  146. public EntityReference createEntityReference(String name)
  147. throws DOMException;
  148. /**
  149. * Returns a <code>NodeList</code> of all the <code>Elements</code> with a
  150. * given tag name in the order in which they are encountered in a
  151. * preorder traversal of the <code>Document</code> tree.
  152. * @param tagname The name of the tag to match on. The special value "*"
  153. * matches all tags.
  154. * @return A new <code>NodeList</code> object containing all the matched
  155. * <code>Elements</code>.
  156. */
  157. public NodeList getElementsByTagName(String tagname);
  158. /**
  159. * Imports a node from another document to this document. The returned
  160. * node has no parent; (<code>parentNode</code> is <code>null</code>).
  161. * The source node is not altered or removed from the original document;
  162. * this method creates a new copy of the source node.
  163. * <br>For all nodes, importing a node creates a node object owned by the
  164. * importing document, with attribute values identical to the source
  165. * node's <code>nodeName</code> and <code>nodeType</code>, plus the
  166. * attributes related to namespaces (<code>prefix</code>,
  167. * <code>localName</code>, and <code>namespaceURI</code>). As in the
  168. * <code>cloneNode</code> operation on a <code>Node</code>, the source
  169. * node is not altered.
  170. * <br>Additional information is copied as appropriate to the
  171. * <code>nodeType</code>, attempting to mirror the behavior expected if
  172. * a fragment of XML or HTML source was copied from one document to
  173. * another, recognizing that the two documents may have different DTDs
  174. * in the XML case. The following list describes the specifics for each
  175. * type of node.
  176. * <dl>
  177. * <dt>ATTRIBUTE_NODE</dt>
  178. * <dd>The <code>ownerElement</code> attribute
  179. * is set to <code>null</code> and the <code>specified</code> flag is
  180. * set to <code>true</code> on the generated <code>Attr</code>. The
  181. * descendants of the source <code>Attr</code> are recursively imported
  182. * and the resulting nodes reassembled to form the corresponding subtree.
  183. * Note that the <code>deep</code> parameter has no effect on
  184. * <code>Attr</code> nodes; they always carry their children with them
  185. * when imported.</dd>
  186. * <dt>DOCUMENT_FRAGMENT_NODE</dt>
  187. * <dd>If the <code>deep</code> option
  188. * was set to <code>true</code>, the descendants of the source element
  189. * are recursively imported and the resulting nodes reassembled to form
  190. * the corresponding subtree. Otherwise, this simply generates an empty
  191. * <code>DocumentFragment</code>.</dd>
  192. * <dt>DOCUMENT_NODE</dt>
  193. * <dd><code>Document</code>
  194. * nodes cannot be imported.</dd>
  195. * <dt>DOCUMENT_TYPE_NODE</dt>
  196. * <dd><code>DocumentType</code>
  197. * nodes cannot be imported.</dd>
  198. * <dt>ELEMENT_NODE</dt>
  199. * <dd>Specified attribute nodes of the
  200. * source element are imported, and the generated <code>Attr</code>
  201. * nodes are attached to the generated <code>Element</code>. Default
  202. * attributes are not copied, though if the document being imported into
  203. * defines default attributes for this element name, those are assigned.
  204. * If the <code>importNode</code> <code>deep</code> parameter was set to
  205. * <code>true</code>, the descendants of the source element are
  206. * recursively imported and the resulting nodes reassembled to form the
  207. * corresponding subtree.</dd>
  208. * <dt>ENTITY_NODE</dt>
  209. * <dd><code>Entity</code> nodes can be
  210. * imported, however in the current release of the DOM the
  211. * <code>DocumentType</code> is readonly. Ability to add these imported
  212. * nodes to a <code>DocumentType</code> will be considered for addition
  213. * to a future release of the DOM.On import, the <code>publicId</code>,
  214. * <code>systemId</code>, and <code>notationName</code> attributes are
  215. * copied. If a <code>deep</code> import is requested, the descendants
  216. * of the the source <code>Entity</code> are recursively imported and
  217. * the resulting nodes reassembled to form the corresponding subtree.</dd>
  218. * <dt>
  219. * ENTITY_REFERENCE_NODE</dt>
  220. * <dd>Only the <code>EntityReference</code> itself is
  221. * copied, even if a <code>deep</code> import is requested, since the
  222. * source and destination documents might have defined the entity
  223. * differently. If the document being imported into provides a
  224. * definition for this entity name, its value is assigned.</dd>
  225. * <dt>NOTATION_NODE</dt>
  226. * <dd>
  227. * <code>Notation</code> nodes can be imported, however in the current
  228. * release of the DOM the <code>DocumentType</code> is readonly. Ability
  229. * to add these imported nodes to a <code>DocumentType</code> will be
  230. * considered for addition to a future release of the DOM.On import, the
  231. * <code>publicId</code> and <code>systemId</code> attributes are copied.
  232. * Note that the <code>deep</code> parameter has no effect on
  233. * <code>Notation</code> nodes since they never have any children.</dd>
  234. * <dt>
  235. * PROCESSING_INSTRUCTION_NODE</dt>
  236. * <dd>The imported node copies its
  237. * <code>target</code> and <code>data</code> values from those of the
  238. * source node.</dd>
  239. * <dt>TEXT_NODE, CDATA_SECTION_NODE, COMMENT_NODE</dt>
  240. * <dd>These three
  241. * types of nodes inheriting from <code>CharacterData</code> copy their
  242. * <code>data</code> and <code>length</code> attributes from those of
  243. * the source node.</dd>
  244. * </dl>
  245. * @param importedNode The node to import.
  246. * @param deep If <code>true</code>, recursively import the subtree under
  247. * the specified node; if <code>false</code>, import only the node
  248. * itself, as explained above. This has no effect on <code>Attr</code>
  249. * , <code>EntityReference</code>, and <code>Notation</code> nodes.
  250. * @return The imported node that belongs to this <code>Document</code>.
  251. * @exception DOMException
  252. * NOT_SUPPORTED_ERR: Raised if the type of node being imported is not
  253. * supported.
  254. * @since DOM Level 2
  255. */
  256. public Node importNode(Node importedNode,
  257. boolean deep)
  258. throws DOMException;
  259. /**
  260. * Creates an element of the given qualified name and namespace URI.
  261. * @param namespaceURI The namespace URI of the element to create.
  262. * @param qualifiedName The qualified name of the element type to
  263. * instantiate.
  264. * @return A new <code>Element</code> object with the following
  265. * attributes:
  266. * <table border='1' summary="Description of attributes and values for the new Element object">
  267. * <tr>
  268. * <th>Attribute</th>
  269. * <th>Value</th>
  270. * </tr>
  271. * <tr>
  272. * <td valign='top'><code>Node.nodeName</code></td>
  273. * <td valign='top'>
  274. * <code>qualifiedName</code></td>
  275. * </tr>
  276. * <tr>
  277. * <td valign='top'><code>Node.namespaceURI</code></td>
  278. * <td valign='top'>
  279. * <code>namespaceURI</code></td>
  280. * </tr>
  281. * <tr>
  282. * <td valign='top'><code>Node.prefix</code></td>
  283. * <td valign='top'>prefix, extracted
  284. * from <code>qualifiedName</code>, or <code>null</code> if there is
  285. * no prefix</td>
  286. * </tr>
  287. * <tr>
  288. * <td valign='top'><code>Node.localName</code></td>
  289. * <td valign='top'>local name, extracted from
  290. * <code>qualifiedName</code></td>
  291. * </tr>
  292. * <tr>
  293. * <td valign='top'><code>Element.tagName</code></td>
  294. * <td valign='top'>
  295. * <code>qualifiedName</code></td>
  296. * </tr>
  297. * </table>
  298. * @exception DOMException
  299. * INVALID_CHARACTER_ERR: Raised if the specified qualified name
  300. * contains an illegal character, per the XML 1.0 specification .
  301. * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is
  302. * malformed per the Namespaces in XML specification, if the
  303. * <code>qualifiedName</code> has a prefix and the
  304. * <code>namespaceURI</code> is <code>null</code>, or if the
  305. * <code>qualifiedName</code> has a prefix that is "xml" and the
  306. * <code>namespaceURI</code> is different from "
  307. * http://www.w3.org/XML/1998/namespace" .
  308. * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
  309. * support the <code>"XML"</code> feature, since namespaces were
  310. * defined by XML.
  311. * @since DOM Level 2
  312. */
  313. public Element createElementNS(String namespaceURI,
  314. String qualifiedName)
  315. throws DOMException;
  316. /**
  317. * Creates an attribute of the given qualified name and namespace URI.
  318. * @param namespaceURI The namespace URI of the attribute to create.
  319. * @param qualifiedName The qualified name of the attribute to
  320. * instantiate.
  321. * @return A new <code>Attr</code> object with the following attributes:
  322. * <table border='1' summary="Description of attributes and values for the new Attr object">
  323. * <tr>
  324. * <th>
  325. * Attribute</th>
  326. * <th>Value</th>
  327. * </tr>
  328. * <tr>
  329. * <td valign='top'><code>Node.nodeName</code></td>
  330. * <td valign='top'>qualifiedName</td>
  331. * </tr>
  332. * <tr>
  333. * <td valign='top'>
  334. * <code>Node.namespaceURI</code></td>
  335. * <td valign='top'><code>namespaceURI</code></td>
  336. * </tr>
  337. * <tr>
  338. * <td valign='top'>
  339. * <code>Node.prefix</code></td>
  340. * <td valign='top'>prefix, extracted from
  341. * <code>qualifiedName</code>, or <code>null</code> if there is no
  342. * prefix</td>
  343. * </tr>
  344. * <tr>
  345. * <td valign='top'><code>Node.localName</code></td>
  346. * <td valign='top'>local name, extracted from
  347. * <code>qualifiedName</code></td>
  348. * </tr>
  349. * <tr>
  350. * <td valign='top'><code>Attr.name</code></td>
  351. * <td valign='top'>
  352. * <code>qualifiedName</code></td>
  353. * </tr>
  354. * <tr>
  355. * <td valign='top'><code>Node.nodeValue</code></td>
  356. * <td valign='top'>the empty
  357. * string</td>
  358. * </tr>
  359. * </table>
  360. * @exception DOMException
  361. * INVALID_CHARACTER_ERR: Raised if the specified qualified name
  362. * contains an illegal character, per the XML 1.0 specification .
  363. * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is
  364. * malformed per the Namespaces in XML specification, if the
  365. * <code>qualifiedName</code> has a prefix and the
  366. * <code>namespaceURI</code> is <code>null</code>, if the
  367. * <code>qualifiedName</code> has a prefix that is "xml" and the
  368. * <code>namespaceURI</code> is different from "
  369. * http://www.w3.org/XML/1998/namespace", or if the
  370. * <code>qualifiedName</code>, or its prefix, is "xmlns" and the
  371. * <code>namespaceURI</code> is different from "
  372. * http://www.w3.org/2000/xmlns/".
  373. * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
  374. * support the <code>"XML"</code> feature, since namespaces were
  375. * defined by XML.
  376. * @since DOM Level 2
  377. */
  378. public Attr createAttributeNS(String namespaceURI,
  379. String qualifiedName)
  380. throws DOMException;
  381. /**
  382. * Returns a <code>NodeList</code> of all the <code>Elements</code> with a
  383. * given local name and namespace URI in the order in which they are
  384. * encountered in a preorder traversal of the <code>Document</code> tree.
  385. * @param namespaceURI The namespace URI of the elements to match on. The
  386. * special value "*" matches all namespaces.
  387. * @param localName The local name of the elements to match on. The
  388. * special value "*" matches all local names.
  389. * @return A new <code>NodeList</code> object containing all the matched
  390. * <code>Elements</code>.
  391. * @since DOM Level 2
  392. */
  393. public NodeList getElementsByTagNameNS(String namespaceURI,
  394. String localName);
  395. /**
  396. * Returns the <code>Element</code> whose <code>ID</code> is given by
  397. * <code>elementId</code>. If no such element exists, returns
  398. * <code>null</code>. Behavior is not defined if more than one element
  399. * has this <code>ID</code>. The DOM implementation must have
  400. * information that says which attributes are of type ID. Attributes
  401. * with the name "ID" are not of type ID unless so defined.
  402. * Implementations that do not know whether attributes are of type ID or
  403. * not are expected to return <code>null</code>.
  404. * @param elementId The unique <code>id</code> value for an element.
  405. * @return The matching element.
  406. * @since DOM Level 2
  407. */
  408. public Element getElementById(String elementId);
  409. }