source: NonGTP/Xerces/xercesc/dom/deprecated/DOM_Document.hpp @ 188

Revision 188, 25.2 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

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