source: NonGTP/Xerces/xerces/include/xercesc/dom/deprecated/DOM_Document.hpp @ 358

Revision 358, 23.2 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 1999-2002,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * $Id: DOM_Document.hpp,v 1.6 2004/09/08 13:55:42 peiyongz Exp $
19*/
20
21#ifndef DOM_Document_HEADER_GUARD_
22#define DOM_Document_HEADER_GUARD_
23
24#include <xercesc/util/XercesDefs.hpp>
25#include "DOM_DocumentType.hpp"
26#include "DOM_DOMImplementation.hpp"
27#include "DOM_Element.hpp"
28#include "DOM_DocumentFragment.hpp"
29#include "DOM_Comment.hpp"
30#include "DOM_CDATASection.hpp"
31#include "DOM_ProcessingInstruction.hpp"
32#include "DOM_Attr.hpp"
33#include "DOM_Entity.hpp"
34#include "DOM_EntityReference.hpp"
35#include "DOM_NodeList.hpp"
36#include "DOM_Notation.hpp"
37#include "DOM_Text.hpp"
38#include "DOM_Node.hpp"
39#include "DOM_NodeIterator.hpp"
40#include "DOM_TreeWalker.hpp"
41#include "DOM_XMLDecl.hpp"
42#include "DOM_Range.hpp"
43
44XERCES_CPP_NAMESPACE_BEGIN
45
46
47class DocumentImpl;
48class NodeIteratorImpl;
49
50
51/**
52* Class to refer to XML Document nodes in the DOM.
53*
54* Conceptually, a DOM document node is the root of the document tree, and provides
55* the  primary access to the document's data.
56* <p>Since elements, text nodes, comments, processing instructions, etc.
57* cannot exist outside the context of a <code>Document</code>, the
58* <code>Document</code> interface also contains the factory methods needed
59* to create these objects.  The <code>Node</code> objects created have a
60* <code>ownerDocument</code> attribute which associates them with the
61* <code>Document</code> within whose  context they were created.
62*/
63class DEPRECATED_DOM_EXPORT DOM_Document: public DOM_Node {
64
65public:
66    /** @name Constructors and assignment operators */
67    //@{
68    /**
69     * The default constructor for DOM_Document creates a null
70     * DOM_Document object that refers to no document.  It may subsequently be
71     * assigned to refer to an actual Document node.
72     *
73     * To create a new document, use the static method
74     *   <code> DOM_Document::createDocument(). </code>
75     *
76     */
77    DOM_Document();
78
79    /**
80      * Copy constructor.  Creates a new <code>DOM_Document</code> that refers to the
81      * same underlying actual document as the original.
82      *
83      * @param other The object to be copied
84      */
85    DOM_Document(const DOM_Document &other);
86    /**
87      * Assignment operator
88      *
89      * @param other The object to be copied
90      */
91    DOM_Document & operator = (const DOM_Document &other);
92
93    /**
94      * Assignment operator.  This overloaded variant is provided for
95      *   the sole purpose of setting a DOM_Node reference variable to
96      *   zero.  Nulling out a reference variable in this way will decrement
97      *   the reference count on the underlying Node object that the variable
98      *   formerly referenced.  This effect is normally obtained when reference
99      *   variable goes out of scope, but zeroing them can be useful for
100      *   global instances, or for local instances that will remain in scope
101      *   for an extended time,  when the storage belonging to the underlying
102      *   node needs to be reclaimed.
103      *
104      * @param val   Only a value of 0, or null, is allowed.
105      */
106    DOM_Document & operator = (const DOM_NullPtr *val);
107
108
109
110        //@}
111  /** @name Destructor */
112  //@{
113       
114  /**
115    * Destructor.  The object being destroyed is the reference
116    * object, not the underlying Document itself.
117    *
118    * <p>The reference counting memory management will
119    *  delete the underlying document itself if this
120    * DOM_Document is the last remaining to refer to the Document,
121    * and if there are no remaining references to any of the nodes
122    * within the document tree.  If other live references do remain,
123    * the underlying document itself remains also.
124    *
125    */
126    ~DOM_Document();
127
128  //@}
129  /** @name Factory methods to create new nodes for the Document */
130  //@{
131
132    /**
133    *   Create a new empty document.
134    *
135    *   This differs from the <code> DOM_Document </code> default
136    *   constructor, which creates
137    *   a null reference only, not an actual document.
138    *
139    *   <p>This function is an extension to the DOM API, which
140    *   lacks any mechanism for the creation of new documents.
141    *   @return A new <code>DOM_Document</code>, which may then
142    *   be populated using the DOM API calls.
143    */
144    static DOM_Document   createDocument(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
145
146    /**
147    *  Create a new entity.
148    *
149    *  Non-standard extension.
150    * @param name The name of the entity to instantiate
151    *
152    */
153    DOM_Entity     createEntity(const DOMString &name);
154
155    /**
156    * Creates an element of the type specified.
157    *
158    * Note that the instance returned
159    * implements the Element interface, so attributes can be specified
160    * directly  on the returned object.
161    * @param tagName The name of the element type to instantiate.
162    * @return A <code>DOM_Element</code> that reference the new element.
163    * @exception DOMException
164    *   INVALID_CHARACTER_ERR: Raised if the specified name contains an
165    *   illegal character.
166    */
167    DOM_Element     createElement(const DOMString &tagName);
168
169    /**
170    * Creates an element of the type specified.
171    * This non-standard overload of createElement, with the name specified as
172    * raw Unicode string, is intended for use from XML parsers,
173    * and is the best performing way to create elements.  The name
174    * string is not checked for conformance to the XML rules for valid
175    * element names.
176    *
177    *
178    * @param tagName The name of the element type to instantiate, as
179    *    a null-terminated unicode string.
180    * @return A new <CODE>DOM_Element</CODE>
181    *        object with the <CODE>nodeName</CODE> attribute set to
182    *        <CODE>tagName</CODE>, and <CODE>localName</CODE>,
183    *        <CODE>prefix</CODE>, and <CODE>namespaceURI</CODE> set to
184    *        <CODE>null</CODE>.
185    */
186    DOM_Element     createElement(const XMLCh *tagName);
187
188
189    /**
190    * Creates an empty DocumentFragment object.
191    *
192    * @return A <code>DOM_DocumentFragment</code> that references the newly
193    * created document fragment.
194    */
195    DOM_DocumentFragment   createDocumentFragment();
196
197    /**
198    * Creates a Text node given the specified string.
199    *
200    * @param data The data for the node.
201    * @return A <code>DOM_Text</code> object that references the newly
202    *  created text node.
203    */
204    DOM_Text         createTextNode(const DOMString &data);
205
206    /**
207    * Creates a Comment node given the specified string.
208    *
209    * @param data The data for the comment.
210    * @return A <code>DOM_Comment</code> that references the newly
211    *  created comment node.
212    */
213    DOM_Comment      createComment(const DOMString &data);
214
215    /**
216    * Creates a CDATASection node whose value  is the specified
217    * string.
218    *
219    * @param data The data for the <code>DOM_CDATASection</code> contents.
220    * @return A <code>DOM_CDATASection</code> object.
221    * @exception DOMException
222    *   NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
223    */
224    DOM_CDATASection   createCDATASection(const DOMString &data);
225
226    /**
227    *  Create a DocumentType node.  Non-standard extension.
228    *
229    * @return A <code>DOM_DocumentType</code> that references the newly
230    *  created DocumentType node.
231    *
232    */
233    DOM_DocumentType createDocumentType(const DOMString &name);
234
235
236    /**
237    *  Create a Notation.
238    *
239    *  Non-standard extension.
240    *
241    *  @param name The name of the notation to instantiate
242    * @return A <code>DOM_Notation</code> that references the newly
243    *  created Notation node.
244    */
245    DOM_Notation createNotation(const DOMString &name);
246
247
248    /**
249    * Creates a ProcessingInstruction node given the specified
250    * name and data strings.
251    *
252    * @param target The target part of the processing instruction.
253    * @param data The data for the node.
254    * @return A <code>DOM_ProcessingInstruction</code> that references the newly
255    *  created PI node.
256    * @exception DOMException
257    *   INVALID_CHARACTER_ERR: Raised if an illegal character is specified.
258    */
259    DOM_ProcessingInstruction createProcessingInstruction(const DOMString &target,
260        const DOMString &data);
261
262
263    /**
264     * Creates an Attr of the given name.
265     *
266     * Note that the
267     * <code>Attr</code> instance can then be attached to an Element
268     * using the <code>DOMElement::setAttribute()</code> method.
269     * @param name The name of the attribute.
270     * @return A new <CODE>DOM_Attr</CODE>
271     *       object with the <CODE>nodeName</CODE> attribute set to
272     *       <CODE>name</CODE>, and <CODE>localName</CODE>, <CODE>prefix</CODE>,
273     *       and <CODE>namespaceURI</CODE> set to
274     *       <CODE>null</CODE>.
275     * @exception DOMException
276     *   INVALID_CHARACTER_ERR: Raised if the specified name contains an
277     *   illegal character.
278     */
279    DOM_Attr     createAttribute(const DOMString &name);
280
281
282    /**
283     * Creates an EntityReference object.
284     *
285     * @param name The name of the entity to reference.
286     * @return A <code>DOM_EntityReference</code> that references the newly
287     *  created EntityReference node.
288     * @exception DOMException
289     *   INVALID_CHARACTER_ERR: Raised if the specified name contains an
290     *   illegal character.
291     */
292    DOM_EntityReference    createEntityReference(const DOMString &name);
293
294
295    /**
296     * Creates a NodeIterator object.   (DOM2)
297     *
298     * NodeIterators are used to step through a set of nodes, e.g. the set of nodes in a NodeList, the
299     * document subtree governed by a particular node, the results of a query, or any other set of nodes.
300     * The set of nodes to be iterated is determined by the implementation of the NodeIterator. DOM Level 2
301     * specifies a single NodeIterator implementation for document-order traversal of a document subtree.
302     * Instances of these iterators are created by calling <code>DocumentTraversal.createNodeIterator()</code>.
303     *
304     * To produce a view of the document that has entity references expanded and does not
305     * expose the entity reference node itself, use the <code>whatToShow</code> flags to hide the entity
306     * reference node and set expandEntityReferences to true when creating the iterator. To
307     * produce a view of the document that has entity reference nodes but no entity expansion,
308     * use the <code>whatToShow</code> flags to show the entity reference node and set
309     * expandEntityReferences to false.
310     *
311     * @param root The root node of the DOM tree
312     * @param whatToShow This attribute determines which node types are presented via the iterator.
313     * @param filter The filter used to screen nodes
314     * @param entityReferenceExpansion The value of this flag determines whether the children of entity reference nodes are
315     *                   visible to the iterator. If false, they will be skipped over.
316     */
317
318    DOM_NodeIterator createNodeIterator(DOM_Node root,
319                                        unsigned long whatToShow,
320                                        DOM_NodeFilter*  filter,
321                                        bool entityReferenceExpansion);
322     /**
323     * Creates a TreeWalker object.   (DOM2)
324     *
325     * TreeWalker objects are used to navigate a document tree or subtree using the view of the document defined
326     * by its whatToShow flags and any filters that are defined for the TreeWalker. Any function which performs
327     * navigation using a TreeWalker will automatically support any view defined by a TreeWalker.
328     *
329     * Omitting nodes from the logical view of a subtree can result in a structure that is substantially different from
330     * the same subtree in the complete, unfiltered document. Nodes that are siblings in the TreeWalker view may
331     * be children of different, widely separated nodes in the original view. For instance, consider a Filter that skips
332     * all nodes except for Text nodes and the root node of a document. In the logical view that results, all text
333     * nodes will be siblings and appear as direct children of the root node, no matter how deeply nested the
334     * structure of the original document.
335     *
336     * To produce a view of the document that has entity references expanded
337     * and does not expose the entity reference node itself, use the whatToShow
338     * flags to hide the entity reference node and set <code>expandEntityReferences</code> to
339     * true when creating the TreeWalker. To produce a view of the document
340     * that has entity reference nodes but no entity expansion, use the
341     * <code>whatToShow</code> flags to show the entity reference node and set
342     * <code>expandEntityReferences</code> to false
343     *
344     * @param root The root node of the DOM tree
345     * @param whatToShow This attribute determines which node types are presented via the tree-walker.
346     * @param filter The filter used to screen nodes
347     * @param entityReferenceExpansion The value of this flag determines whether the children of entity reference nodes are
348     *                   visible to the tree-walker. If false, they will be skipped over.
349     */
350
351    DOM_TreeWalker  createTreeWalker(DOM_Node root,
352                                     unsigned long whatToShow,
353                                     DOM_NodeFilter*  filter,
354                                     bool entityReferenceExpansion);
355
356    /**
357     * Creates a XMLDecl type Node .   Non-Standard (an extension to xerces)
358     *
359     * XMLDecl Nodes are created to get  version, encoding and standalone information in a document tree
360     *
361     * This node if created gets attached to a document object or an entity node. There can be no child
362     * to this type of node.
363     *
364     * @param version The version data of the document. Currently possible value is 1.0
365     * @param encoding The encoding type specified in the document
366     * @param standalone The information whether the document is standalone or not
367     */
368
369    DOM_XMLDecl createXMLDecl(const DOMString& version,
370                            const DOMString& encoding,
371                            const DOMString& standalone);
372
373    /**
374          * To create the range  consisting of boundary-points and offset of the
375      * selected contents
376      *
377      * @return The initial state of the Range such that both the boundary-points
378      * are positioned at the beginning of the corresponding DOM_DOcument, before
379      * any content. The range returned can only be used to select content
380      * associated with this document, or with documentFragments and Attrs for
381      * which this document is the ownerdocument
382          */
383    DOM_Range    createRange();
384
385    //@}
386    /** @name Getter functions */
387    //@{
388    /**
389     * Get Document Type Declaration (see <code>DOM_DocumentType</code>) associated
390     * with  this document.
391     *
392     * For documents without
393     * a document type declaration this returns <code>null</code> reference object. The DOM Level
394     *  1 does not support editing the Document Type Declaration, therefore
395     * <code>docType</code> cannot be altered in any way.
396     */
397    DOM_DocumentType       getDoctype() const;
398
399
400
401    /**
402     * Return the <code>DOMImplementation</code> object that handles this document.
403     */
404    DOM_DOMImplementation  &getImplementation() const;
405
406
407    /**
408     * Return a reference to the root element of the document.
409     */
410    DOM_Element     getDocumentElement() const;
411
412    /**
413     * Returns a <code>DOM_NodeList</code> of all the elements with a
414     * given tag name.  The returned node list is "live", in that changes
415     * to the document tree made after a nodelist was initially
416     * returned will be immediately reflected in the node list.
417     *
418     * The elements in the node list are ordered in the same order in which they
419     * would be encountered in a
420     * preorder traversal of the <code>Document</code> tree.
421     * @param tagname The name of the tag to match on. The special value "*"
422     *   matches all tags.
423     * @return A reference to a NodeList containing all the matched
424     *   <code>Element</code>s.
425     */
426    DOM_NodeList           getElementsByTagName(const DOMString &tagname) const;
427
428    //@}
429    /** @name Functions introduced in DOM Level 2. */
430    //@{
431
432    /**
433     * Imports a node from another document to this document.
434     * The returned node has no parent (<CODE>parentNode</CODE> is
435     * <CODE>null</CODE>). The source node is not altered or removed from the
436     * original document; this method creates a new copy of the source
437     * node.<BR>For all nodes, importing a node creates a node object owned by
438     * the importing document, with attribute values identical to the source
439     * node's <CODE>nodeName</CODE> and <CODE>nodeType</CODE>, plus the
440     * attributes related to namespaces (prefix and namespaces URI).
441     *
442     * @param importedNode The node to import.
443     * @param deep If <CODE>true</CODE>, recursively import the subtree under the
444     *      specified node; if <CODE>false</CODE>, import only the node itself,
445     *      as explained above. This does not apply to <CODE>DOM_Attr</CODE>,
446     *      <CODE>DOM_EntityReference</CODE>, and <CODE>DOM_Notation</CODE> nodes.
447     * @return The imported node that belongs to this <CODE>DOM_Document</CODE>.
448     * @exception DOMException
449     *   NOT_SUPPORTED_ERR: Raised if the type of node being imported is
450     *                      not supported.
451     */
452    DOM_Node            importNode(const DOM_Node &importedNode, bool deep);
453
454    /**
455     * Creates an element of the given qualified name and
456     * namespace URI.
457     *
458     * @param namespaceURI The <em>namespace URI</em> of
459     *   the element to create.
460     * @param qualifiedName The <em>qualified name</em>
461     *   of the element type to instantiate.
462     * @return A new <code>DOM_Element</code> object.
463     * @exception DOMException
464     *   INVALID_CHARACTER_ERR: Raised if the specified qualified name contains
465     *                          an illegal character.
466     * <br>
467     *   NAMESPACE_ERR: Raised if the <CODE>qualifiedName</CODE> is
468     *      malformed, if the <CODE>qualifiedName</CODE> has a prefix and the
469     *      <CODE>namespaceURI</CODE> is <CODE>null</CODE> or an empty string,
470     *      or if the <CODE>qualifiedName</CODE> has a prefix that is "xml" and
471     *      the <CODE>namespaceURI</CODE> is different from
472     *      "http://www.w3.org/XML/1998/namespace".
473     */
474    DOM_Element         createElementNS(const DOMString &namespaceURI,
475        const DOMString &qualifiedName);
476
477    /**
478     * Creates an attribute of the given qualified name and namespace
479     * URI.
480     *
481     * @param namespaceURI The <em>namespace URI</em> of
482     *   the attribute to create.
483     * @param qualifiedName The <em>qualified name</em>
484     *   of the attribute to instantiate.
485     * @return A new <code>DOM_Attr</code> object.
486     * @exception DOMException
487     *   INVALID_CHARACTER_ERR: Raised if the specified qualified name contains
488     *                          an illegal character.
489     * <br>
490     *   NAMESPACE_ERR: Raised if the <CODE>qualifiedName</CODE> is
491     *      malformed, if the <CODE>qualifiedName</CODE> has a prefix and the
492     *      <CODE>namespaceURI</CODE> is <CODE>null</CODE> or an empty string,
493     *      if the <CODE>qualifiedName</CODE> has a prefix that is "xml" and the
494     *      <CODE>namespaceURI</CODE> is different from
495     *      "http://www.w3.org/XML/1998/namespace", if the
496     *      <CODE>qualifiedName</CODE> has a prefix that is "xmlns" and the
497     *      <CODE>namespaceURI</CODE> is different from
498     *      "http://www.w3.org/2000/xmlns/", or if the
499     *      <CODE>qualifiedName</CODE> is "xmlns" and the
500     *      <CODE>namespaceURI</CODE> is different from
501     *      "http://www.w3.org/2000/xmlns/".
502     */
503    DOM_Attr            createAttributeNS(const DOMString &namespaceURI,
504        const DOMString &qualifiedName);
505
506    /**
507     * Returns a <code>DOM_NodeList</code> of all the <code>DOM_Element</code>s
508     * with a given <em>local name</em> and
509     * namespace URI in the order in which they would be encountered in a
510     * preorder traversal of the <code>DOM_Document</code> tree.
511     *
512     * @param namespaceURI The <em>namespace URI</em> of
513     *   the elements to match on. The special value "*" matches all
514     *   namespaces.
515     * @param localName The <em>local name</em> of the
516     *   elements to match on. The special value "*" matches all local names.
517     * @return A new <code>DOM_NodeList</code> object containing all the matched
518     *  <code>DOM_Element</code>s.
519     */
520    DOM_NodeList        getElementsByTagNameNS(const DOMString &namespaceURI,
521        const DOMString &localName) const;
522
523    /**
524     * Returns the <code>DOM_Element</code> whose ID is given by <code>elementId</code>.
525     * If no such element exists, returns <code>null</code>.
526     * Behavior is not defined if more than one element has this <code>ID</code>.
527     * <P><B>Note:</B> The DOM implementation must have information that says
528     * which attributes are of type ID. Attributes with the name "ID" are not of
529     * type ID unless so defined. Implementations that do not know whether
530     * attributes are of type ID or not are expected to return
531     * <CODE>null</CODE>.</P>
532     *
533     * @param elementId The unique <code>id</code> value for an element.
534     * @return The matching element.
535     */
536    DOM_Element         getElementById(const DOMString &elementId);
537
538    /**
539     * Sets whether the DOM implementation performs error checking
540     * upon operations. Turning off error checking only affects
541     * the following DOM checks:
542     * <ul>
543     * <li>Checking strings to make sure that all characters are
544     *     legal XML characters
545     * <li>Hierarchy checking such as allowed children, checks for
546     *     cycles, etc.
547     * </ul>
548     * <p>
549     * Turning off error checking does <em>not</em> turn off the
550     * following checks:
551     * <ul>
552     * <li>Read only checks
553     * <li>Checks related to DOM events
554     * </ul>
555     */
556    void setErrorChecking(bool check);
557
558    /**
559     * Returns true if the DOM implementation performs error checking.
560     */
561    bool getErrorChecking();
562
563    //@}
564
565protected:
566    DOM_Document (DocumentImpl *impl);
567
568    friend class DOM_Node;
569    friend class DocumentImpl;
570    friend class NodeIteratorImpl;
571    friend class DOM_DOMImplementation;
572
573};
574
575
576XERCES_CPP_NAMESPACE_END
577
578#endif
Note: See TracBrowser for help on using the repository browser.