source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/dom/deprecated/DOM_Document.hpp @ 2674

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