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 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) 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 dataThe 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 dataThe 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 dataThe 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 targetThe target part of the processing instruction.
111: * @param dataThe 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 nameThe 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 nameThe 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 tagnameThe 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: *
256: * @param importedNodeThe node to import.
257: * @param deepIf <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: * HTML-only DOM implementations do not need to implement this method.
273: * @param namespaceURIThe namespace URI of the element to create.
274: * @param qualifiedNameThe qualified name of the element type to
275: * instantiate.
276: * @return A new <code>Element</code> object with the following
277: * attributes:AttributeValue<code>Node.nodeName</code>
278: * <code>qualifiedName</code><code>Node.namespaceURI</code>
279: * <code>namespaceURI</code><code>Node.prefix</code>prefix, extracted
280: * from <code>qualifiedName</code>, or <code>null</code> if there is
281: * no prefix<code>Node.localName</code>local name, extracted from
282: * <code>qualifiedName</code><code>Element.tagName</code>
283: * <code>qualifiedName</code>
284: * @exception DOMException
285: * INVALID_CHARACTER_ERR: Raised if the specified qualified name
286: * contains an illegal character.
287: * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is
288: * malformed, if the <code>qualifiedName</code> has a prefix and the
289: * <code>namespaceURI</code> is <code>null</code>, or if the
290: * <code>qualifiedName</code> has a prefix that is "xml" and the
291: * <code>namespaceURI</code> is different from "
292: * http://www.w3.org/XML/1998/namespace" .
293: * @since DOM Level 2
294: */
295: public Element createElementNS(String namespaceURI,
296: String qualifiedName) throws DOMException;
297:
298: /**
299: * Creates an attribute of the given qualified name and namespace URI.
300: * HTML-only DOM implementations do not need to implement this method.
301: * @param namespaceURIThe namespace URI of the attribute to create.
302: * @param qualifiedNameThe qualified name of the attribute to instantiate.
303: * @return A new <code>Attr</code> object with the following attributes:
304: * AttributeValue<code>Node.nodeName</code>qualifiedName
305: * <code>Node.namespaceURI</code><code>namespaceURI</code>
306: * <code>Node.prefix</code>prefix, extracted from
307: * <code>qualifiedName</code>, or <code>null</code> if there is no
308: * prefix<code>Node.localName</code>local name, extracted from
309: * <code>qualifiedName</code><code>Attr.name</code>
310: * <code>qualifiedName</code><code>Node.nodeValue</code>the empty
311: * string
312: * @exception DOMException
313: * INVALID_CHARACTER_ERR: Raised if the specified qualified name
314: * contains an illegal character.
315: * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is
316: * malformed, if the <code>qualifiedName</code> has a prefix and the
317: * <code>namespaceURI</code> is <code>null</code>, if the
318: * <code>qualifiedName</code> has a prefix that is "xml" and the
319: * <code>namespaceURI</code> is different from "
320: * http://www.w3.org/XML/1998/namespace", or if the
321: * <code>qualifiedName</code> is "xmlns" and the
322: * <code>namespaceURI</code> is different from "
323: * http://www.w3.org/2000/xmlns/".
324: * @since DOM Level 2
325: */
326: public Attr createAttributeNS(String namespaceURI,
327: String qualifiedName) throws DOMException;
328:
329: /**
330: * Returns a <code>NodeList</code> of all the <code>Elements</code> with a
331: * given local name and namespace URI in the order in which they are
332: * encountered in a preorder traversal of the <code>Document</code> tree.
333: * @param namespaceURIThe namespace URI of the elements to match on. The
334: * special value "*" matches all namespaces.
335: * @param localNameThe local name of the elements to match on. The
336: * special value "*" matches all local names.
337: * @return A new <code>NodeList</code> object containing all the matched
338: * <code>Elements</code>.
339: * @since DOM Level 2
340: */
341: public NodeList getElementsByTagNameNS(String namespaceURI,
342: String localName);
343:
344: /**
345: * Returns the <code>Element</code> whose <code>ID</code> is given by
346: * <code>elementId</code>. If no such element exists, returns
347: * <code>null</code>. Behavior is not defined if more than one element
348: * has this <code>ID</code>. The DOM implementation must have
349: * information that says which attributes are of type ID. Attributes
350: * with the name "ID" are not of type ID unless so defined.
351: * Implementations that do not know whether attributes are of type ID or
352: * not are expected to return <code>null</code>.
353: * @param elementIdThe unique <code>id</code> value for an element.
354: * @return The matching element.
355: * @since DOM Level 2
356: */
357: public Element getElementById(String elementId);
358:
359: }
|