001: /*
002: * Copyright (c) 2000 World Wide Web Consortium,
003: * (Massachusetts Institute of Technology, Institut National de
004: * Recherche en Informatique et en Automatique, Keio University). All
005: * Rights Reserved. This program is distributed under the W3C's Software
006: * Intellectual Property License. This program is distributed in the
007: * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
008: * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
009: * PURPOSE.
010: * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
011: */
012:
013: package org.w3c.dom;
014:
015: /**
016: * The <code>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: */
027: public 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 tagName The 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) throws DOMException;
075:
076: /**
077: * Creates an empty <code>DocumentFragment</code> object.
078: * @return A new <code>DocumentFragment</code>.
079: */
080: public DocumentFragment createDocumentFragment();
081:
082: /**
083: * Creates a <code>Text</code> node given the specified string.
084: * @param data The data for the node.
085: * @return The new <code>Text</code> object.
086: */
087: public Text createTextNode(String data);
088:
089: /**
090: * Creates a <code>Comment</code> node given the specified string.
091: * @param data The data for the node.
092: * @return The new <code>Comment</code> object.
093: */
094: public Comment createComment(String data);
095:
096: /**
097: * Creates a <code>CDATASection</code> node whose value is the specified
098: * string.
099: * @param data The data for the <code>CDATASection</code> contents.
100: * @return The new <code>CDATASection</code> object.
101: * @exception DOMException
102: * NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
103: */
104: public CDATASection createCDATASection(String data)
105: throws DOMException;
106:
107: /**
108: * Creates a <code>ProcessingInstruction</code> node given the specified
109: * name and data strings.
110: * @param target The target part of the processing instruction.
111: * @param data The data for the node.
112: * @return The new <code>ProcessingInstruction</code> object.
113: * @exception DOMException
114: * INVALID_CHARACTER_ERR: Raised if the specified target contains an
115: * illegal character.
116: * <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
117: */
118: public ProcessingInstruction createProcessingInstruction(
119: String target, String data) throws DOMException;
120:
121: /**
122: * Creates an <code>Attr</code> of the given name. Note that the
123: * <code>Attr</code> instance can then be set on an <code>Element</code>
124: * using the <code>setAttributeNode</code> method.
125: * <br>To create an attribute with a qualified name and namespace URI, use
126: * the <code>createAttributeNS</code> method.
127: * @param name The name of the attribute.
128: * @return A new <code>Attr</code> object with the <code>nodeName</code>
129: * attribute set to <code>name</code>, and <code>localName</code>,
130: * <code>prefix</code>, and <code>namespaceURI</code> set to
131: * <code>null</code>. The value of the attribute is the empty string.
132: * @exception DOMException
133: * INVALID_CHARACTER_ERR: Raised if the specified name contains an
134: * illegal character.
135: */
136: public Attr createAttribute(String name) throws DOMException;
137:
138: /**
139: * Creates an <code>EntityReference</code> object. In addition, if the
140: * referenced entity is known, the child list of the
141: * <code>EntityReference</code> node is made the same as that of the
142: * corresponding <code>Entity</code> node.If any descendant of the
143: * <code>Entity</code> node has an unbound namespace prefix, the
144: * corresponding descendant of the created <code>EntityReference</code>
145: * node is also unbound; (its <code>namespaceURI</code> is
146: * <code>null</code>). The DOM Level 2 does not support any mechanism to
147: * resolve namespace prefixes.
148: * @param name The name of the entity to reference.
149: * @return The new <code>EntityReference</code> object.
150: * @exception DOMException
151: * INVALID_CHARACTER_ERR: Raised if the specified name contains an
152: * illegal character.
153: * <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
154: */
155: public EntityReference createEntityReference(String name)
156: throws DOMException;
157:
158: /**
159: * Returns a <code>NodeList</code> of all the <code>Elements</code> with a
160: * given tag name in the order in which they are encountered in a
161: * preorder traversal of the <code>Document</code> tree.
162: * @param tagname The name of the tag to match on. The special value "*"
163: * matches all tags.
164: * @return A new <code>NodeList</code> object containing all the matched
165: * <code>Elements</code>.
166: */
167: public NodeList getElementsByTagName(String tagname);
168:
169: /**
170: * Imports a node from another document to this document. The returned
171: * node has no parent; (<code>parentNode</code> is <code>null</code>).
172: * The source node is not altered or removed from the original document;
173: * this method creates a new copy of the source node.
174: * <br>For all nodes, importing a node creates a node object owned by the
175: * importing document, with attribute values identical to the source
176: * node's <code>nodeName</code> and <code>nodeType</code>, plus the
177: * attributes related to namespaces (<code>prefix</code>,
178: * <code>localName</code>, and <code>namespaceURI</code>). As in the
179: * <code>cloneNode</code> operation on a <code>Node</code>, the source
180: * node is not altered.
181: * <br>Additional information is copied as appropriate to the
182: * <code>nodeType</code>, attempting to mirror the behavior expected if
183: * a fragment of XML or HTML source was copied from one document to
184: * another, recognizing that the two documents may have different DTDs
185: * in the XML case. The following list describes the specifics for each
186: * type of node.
187: * <dl>
188: * <dt>ATTRIBUTE_NODE</dt>
189: * <dd>The <code>ownerElement</code> attribute
190: * is set to <code>null</code> and the <code>specified</code> flag is
191: * set to <code>true</code> on the generated <code>Attr</code>. The
192: * descendants of the source <code>Attr</code> are recursively imported
193: * and the resulting nodes reassembled to form the corresponding subtree.
194: * Note that the <code>deep</code> parameter has no effect on
195: * <code>Attr</code> nodes; they always carry their children with them
196: * when imported.</dd>
197: * <dt>DOCUMENT_FRAGMENT_NODE</dt>
198: * <dd>If the <code>deep</code> option
199: * was set to <code>true</code>, the descendants of the source element
200: * are recursively imported and the resulting nodes reassembled to form
201: * the corresponding subtree. Otherwise, this simply generates an empty
202: * <code>DocumentFragment</code>.</dd>
203: * <dt>DOCUMENT_NODE</dt>
204: * <dd><code>Document</code>
205: * nodes cannot be imported.</dd>
206: * <dt>DOCUMENT_TYPE_NODE</dt>
207: * <dd><code>DocumentType</code>
208: * nodes cannot be imported.</dd>
209: * <dt>ELEMENT_NODE</dt>
210: * <dd>Specified attribute nodes of the
211: * source element are imported, and the generated <code>Attr</code>
212: * nodes are attached to the generated <code>Element</code>. Default
213: * attributes are not copied, though if the document being imported into
214: * defines default attributes for this element name, those are assigned.
215: * If the <code>importNode</code> <code>deep</code> parameter was set to
216: * <code>true</code>, the descendants of the source element are
217: * recursively imported and the resulting nodes reassembled to form the
218: * corresponding subtree.</dd>
219: * <dt>ENTITY_NODE</dt>
220: * <dd><code>Entity</code> nodes can be
221: * imported, however in the current release of the DOM the
222: * <code>DocumentType</code> is readonly. Ability to add these imported
223: * nodes to a <code>DocumentType</code> will be considered for addition
224: * to a future release of the DOM.On import, the <code>publicId</code>,
225: * <code>systemId</code>, and <code>notationName</code> attributes are
226: * copied. If a <code>deep</code> import is requested, the descendants
227: * of the the source <code>Entity</code> are recursively imported and
228: * the resulting nodes reassembled to form the corresponding subtree.</dd>
229: * <dt>
230: * ENTITY_REFERENCE_NODE</dt>
231: * <dd>Only the <code>EntityReference</code> itself is
232: * copied, even if a <code>deep</code> import is requested, since the
233: * source and destination documents might have defined the entity
234: * differently. If the document being imported into provides a
235: * definition for this entity name, its value is assigned.</dd>
236: * <dt>NOTATION_NODE</dt>
237: * <dd>
238: * <code>Notation</code> nodes can be imported, however in the current
239: * release of the DOM the <code>DocumentType</code> is readonly. Ability
240: * to add these imported nodes to a <code>DocumentType</code> will be
241: * considered for addition to a future release of the DOM.On import, the
242: * <code>publicId</code> and <code>systemId</code> attributes are copied.
243: * Note that the <code>deep</code> parameter has no effect on
244: * <code>Notation</code> nodes since they never have any children.</dd>
245: * <dt>
246: * PROCESSING_INSTRUCTION_NODE</dt>
247: * <dd>The imported node copies its
248: * <code>target</code> and <code>data</code> values from those of the
249: * source node.</dd>
250: * <dt>TEXT_NODE, CDATA_SECTION_NODE, COMMENT_NODE</dt>
251: * <dd>These three
252: * types of nodes inheriting from <code>CharacterData</code> copy their
253: * <code>data</code> and <code>length</code> attributes from those of
254: * the source node.</dd>
255: * </dl>
256: * @param importedNode The node to import.
257: * @param deep If <code>true</code>, recursively import the subtree under
258: * the specified node; if <code>false</code>, import only the node
259: * itself, as explained above. This has no effect on <code>Attr</code>
260: * , <code>EntityReference</code>, and <code>Notation</code> nodes.
261: * @return The imported node that belongs to this <code>Document</code>.
262: * @exception DOMException
263: * NOT_SUPPORTED_ERR: Raised if the type of node being imported is not
264: * supported.
265: * @since DOM Level 2
266: */
267: public Node importNode(Node importedNode, boolean deep)
268: throws DOMException;
269:
270: /**
271: * Creates an element of the given qualified name and namespace URI.
272: * @param namespaceURI The namespace URI of the element to create.
273: * @param qualifiedName The qualified name of the element type to
274: * instantiate.
275: * @return A new <code>Element</code> object with the following
276: * attributes:
277: * <table border='1'>
278: * <tr>
279: * <th>Attribute</th>
280: * <th>Value</th>
281: * </tr>
282: * <tr>
283: * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeName</code></td>
284: * <td valign='top' rowspan='1' colspan='1'>
285: * <code>qualifiedName</code></td>
286: * </tr>
287: * <tr>
288: * <td valign='top' rowspan='1' colspan='1'><code>Node.namespaceURI</code></td>
289: * <td valign='top' rowspan='1' colspan='1'>
290: * <code>namespaceURI</code></td>
291: * </tr>
292: * <tr>
293: * <td valign='top' rowspan='1' colspan='1'><code>Node.prefix</code></td>
294: * <td valign='top' rowspan='1' colspan='1'>prefix, extracted
295: * from <code>qualifiedName</code>, or <code>null</code> if there is
296: * no prefix</td>
297: * </tr>
298: * <tr>
299: * <td valign='top' rowspan='1' colspan='1'><code>Node.localName</code></td>
300: * <td valign='top' rowspan='1' colspan='1'>local name, extracted from
301: * <code>qualifiedName</code></td>
302: * </tr>
303: * <tr>
304: * <td valign='top' rowspan='1' colspan='1'><code>Element.tagName</code></td>
305: * <td valign='top' rowspan='1' colspan='1'>
306: * <code>qualifiedName</code></td>
307: * </tr>
308: * </table>
309: * @exception DOMException
310: * INVALID_CHARACTER_ERR: Raised if the specified qualified name
311: * contains an illegal character, per the XML 1.0 specification .
312: * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is
313: * malformed per the Namespaces in XML specification, if the
314: * <code>qualifiedName</code> has a prefix and the
315: * <code>namespaceURI</code> is <code>null</code>, or if the
316: * <code>qualifiedName</code> has a prefix that is "xml" and the
317: * <code>namespaceURI</code> is different from "
318: * http://www.w3.org/XML/1998/namespace" .
319: * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
320: * support the <code>"XML"</code> feature, since namespaces were
321: * defined by XML.
322: * @since DOM Level 2
323: */
324: public Element createElementNS(String namespaceURI,
325: String qualifiedName) throws DOMException;
326:
327: /**
328: * Creates an attribute of the given qualified name and namespace URI.
329: * @param namespaceURI The namespace URI of the attribute to create.
330: * @param qualifiedName The qualified name of the attribute to
331: * instantiate.
332: * @return A new <code>Attr</code> object with the following attributes:
333: * <table border='1'>
334: * <tr>
335: * <th>
336: * Attribute</th>
337: * <th>Value</th>
338: * </tr>
339: * <tr>
340: * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeName</code></td>
341: * <td valign='top' rowspan='1' colspan='1'>qualifiedName</td>
342: * </tr>
343: * <tr>
344: * <td valign='top' rowspan='1' colspan='1'>
345: * <code>Node.namespaceURI</code></td>
346: * <td valign='top' rowspan='1' colspan='1'><code>namespaceURI</code></td>
347: * </tr>
348: * <tr>
349: * <td valign='top' rowspan='1' colspan='1'>
350: * <code>Node.prefix</code></td>
351: * <td valign='top' rowspan='1' colspan='1'>prefix, extracted from
352: * <code>qualifiedName</code>, or <code>null</code> if there is no
353: * prefix</td>
354: * </tr>
355: * <tr>
356: * <td valign='top' rowspan='1' colspan='1'><code>Node.localName</code></td>
357: * <td valign='top' rowspan='1' colspan='1'>local name, extracted from
358: * <code>qualifiedName</code></td>
359: * </tr>
360: * <tr>
361: * <td valign='top' rowspan='1' colspan='1'><code>Attr.name</code></td>
362: * <td valign='top' rowspan='1' colspan='1'>
363: * <code>qualifiedName</code></td>
364: * </tr>
365: * <tr>
366: * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeValue</code></td>
367: * <td valign='top' rowspan='1' colspan='1'>the empty
368: * string</td>
369: * </tr>
370: * </table>
371: * @exception DOMException
372: * INVALID_CHARACTER_ERR: Raised if the specified qualified name
373: * contains an illegal character, per the XML 1.0 specification .
374: * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is
375: * malformed per the Namespaces in XML specification, if the
376: * <code>qualifiedName</code> has a prefix and the
377: * <code>namespaceURI</code> is <code>null</code>, if the
378: * <code>qualifiedName</code> has a prefix that is "xml" and the
379: * <code>namespaceURI</code> is different from "
380: * http://www.w3.org/XML/1998/namespace", or if the
381: * <code>qualifiedName</code>, or its prefix, is "xmlns" and the
382: * <code>namespaceURI</code> is different from "
383: * http://www.w3.org/2000/xmlns/".
384: * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
385: * support the <code>"XML"</code> feature, since namespaces were
386: * defined by XML.
387: * @since DOM Level 2
388: */
389: public Attr createAttributeNS(String namespaceURI,
390: String qualifiedName) throws DOMException;
391:
392: /**
393: * Returns a <code>NodeList</code> of all the <code>Elements</code> with a
394: * given local name and namespace URI in the order in which they are
395: * encountered in a preorder traversal of the <code>Document</code> tree.
396: * @param namespaceURI The namespace URI of the elements to match on. The
397: * special value "*" matches all namespaces.
398: * @param localName The local name of the elements to match on. The
399: * special value "*" matches all local names.
400: * @return A new <code>NodeList</code> object containing all the matched
401: * <code>Elements</code>.
402: * @since DOM Level 2
403: */
404: public NodeList getElementsByTagNameNS(String namespaceURI,
405: String localName);
406:
407: /**
408: * Returns the <code>Element</code> whose <code>ID</code> is given by
409: * <code>elementId</code>. If no such element exists, returns
410: * <code>null</code>. Behavior is not defined if more than one element
411: * has this <code>ID</code>. The DOM implementation must have
412: * information that says which attributes are of type ID. Attributes
413: * with the name "ID" are not of type ID unless so defined.
414: * Implementations that do not know whether attributes are of type ID or
415: * not are expected to return <code>null</code>.
416: * @param elementId The unique <code>id</code> value for an element.
417: * @return The matching element.
418: * @since DOM Level 2
419: */
420: public Element getElementById(String elementId);
421:
422: }
|