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

Revision 188, 24.7 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_Node.hpp,v 1.3 2002/11/04 15:04:44 tng Exp $
59 */
60
61#ifndef DOM_Node_HEADER_GUARD_
62#define DOM_Node_HEADER_GUARD_
63
64#include <xercesc/util/XercesDefs.hpp>
65#include "DOMString.hpp"
66
67XERCES_CPP_NAMESPACE_BEGIN
68
69class DOM_NodeList;
70class DOM_NamedNodeMap;
71class DOM_Document;
72class NodeImpl;
73
74class DOM_NullPtr;  // A dummy class, with no implementation, that is
75                    //  used as in overloaded functions as a way to
76                    //  pass 0 or null.
77
78/**
79 * The <code>Node</code> interface is the primary datatype for the entire
80 * Document Object Model.
81 *
82 * It represents a single node in the document tree.
83 * While all objects implementing the <code>Node</code> interface expose
84 * methods for dealing with children, not all objects implementing the
85 * <code>Node</code> interface may have children. For example,
86 * <code>Text</code> nodes may not have children, and adding children to such
87 * nodes results in a <code>DOMException</code> being raised.
88 * <p>The attributes <code>nodeName</code>, <code>nodeValue</code>  and
89 * <code>attributes</code> are  included as a mechanism to get at node
90 * information without  casting down to the specific derived interface. In
91 * cases where  there is no obvious mapping of these attributes for a specific
92 *  <code>nodeType</code> (e.g., <code>nodeValue</code> for an Element  or
93 * <code>attributes</code>  for a Comment), this returns <code>null</code>.
94 * Note that the  specialized interfaces may contain additional and more
95 * convenient mechanisms to get and set the relevant information.
96 */
97class  CDOM_EXPORT DOM_Node {
98
99    public:
100    /** @name Constructors and assignment operators */
101    //@{
102    /**
103      * Default constructor for DOM_Node.  The resulting object does not
104      * refer to an actual  node; it will compare == to 0, and is similar
105      * to a null object reference variable in Java.  It may subsequently be
106      * assigned to refer to an actual node.  "Acutal Nodes" will always
107      * be of some derived type, such as Element or Attr.
108      *
109      */
110    DOM_Node();
111
112    /**
113      * Copy constructor.
114      *
115      * @param other The object to be copied.
116      */
117    DOM_Node(const DOM_Node &other);
118
119    /**
120      * Assignment operator.
121      *
122      * @param other The source to be assigned.
123      */
124    DOM_Node & operator = (const DOM_Node &other);
125
126     /**
127      * Assignment operator.  This overloaded variant is provided for
128      *   the sole purpose of setting a DOM_Node reference variable to
129      *   zero.  Nulling out a reference variable in this way will decrement
130      *   the reference count on the underlying Node object that the variable
131      *   formerly referenced.  This effect is normally obtained when reference
132      *   variable goes out of scope, but zeroing them can be useful for
133      *   global instances, or for local instances that will remain in scope
134      *   for an extended time,  when the storage belonging to the underlying
135      *   node needs to be reclaimed.
136      *
137      * @param val   Only a value of 0, or null, is allowed.
138      */
139    DOM_Node & operator = (const DOM_NullPtr *val);
140
141   //@}
142    /** @name Destructor. */
143    //@{
144         /**
145          * Destructor for DOM_Node.  The object being destroyed is the reference
146      * object, not the underlying node itself.
147          *
148          */
149    ~DOM_Node();
150
151    //@}
152    /** @name Equality and Inequality operators. */
153    //@{
154    /**
155     * The equality operator.  This compares to references to nodes, and
156     * returns true if they both refer to the same underlying node.  It
157     * is exactly analogous to Java's operator ==  on object reference
158     * variables.  This operator can not be used to compare the values
159     * of two different nodes in the document tree.
160     *
161     * @param other The object reference with which <code>this</code> object is compared
162     * @returns True if both <code>DOM_Node</code>s refer to the same
163     *  actual node, or are both null; return false otherwise.
164     */
165    bool operator == (const DOM_Node & other)const;
166
167    /**
168      *  Compare with a pointer.  Intended only to allow a convenient
169      *    comparison with null.
170      *
171      */
172    bool operator == (const DOM_NullPtr *other) const;
173
174    /**
175     * The inequality operator.  See operator ==.
176     *
177     */
178    bool operator != (const DOM_Node & other) const;
179
180     /**
181      *  Compare with a pointer.  Intended only to allow a convenient
182      *    comparison with null.
183      *
184      */
185   bool operator != (const DOM_NullPtr * other) const;
186
187
188    enum NodeType {
189        ELEMENT_NODE                = 1,
190        ATTRIBUTE_NODE              = 2,
191        TEXT_NODE                   = 3,
192        CDATA_SECTION_NODE          = 4,
193        ENTITY_REFERENCE_NODE       = 5,
194        ENTITY_NODE                 = 6,
195        PROCESSING_INSTRUCTION_NODE = 7,
196        COMMENT_NODE                = 8,
197        DOCUMENT_NODE               = 9,
198        DOCUMENT_TYPE_NODE          = 10,
199        DOCUMENT_FRAGMENT_NODE      = 11,
200        NOTATION_NODE               = 12,
201        XML_DECL_NODE               = 13
202    };
203
204    //@}
205    /** @name Get functions. */
206    //@{
207
208    /**
209     * The name of this node, depending on its type; see the table above.
210     */
211    DOMString       getNodeName() const;
212
213    /**
214     * Gets the value of this node, depending on its type.
215     *
216     * @exception DOMException
217     *   NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
218     * @exception DOMException
219     *   DOMSTRING_SIZE_ERR: Raised when it would return more characters than
220     *   fit in a <code>DOMString</code> variable on the implementation
221     *   platform.
222     */
223    DOMString       getNodeValue() const;
224
225    /**
226     * An enum value representing the type of the underlying object.
227     */
228    short           getNodeType() const;
229
230    /**
231     * Gets the parent of this node.
232     *
233     * All nodes, except <code>Document</code>,
234     * <code>DocumentFragment</code>, and <code>Attr</code> may have a parent.
235     * However, if a node has just been created and not yet added to the tree,
236     * or if it has been removed from the tree, a <code>null</code> DOM_Node
237     * is returned.
238     */
239    DOM_Node        getParentNode() const;
240
241    /**
242     * Gets a <code>NodeList</code> that contains all children of this node.
243     *
244     * If there
245     * are no children, this is a <code>NodeList</code> containing no nodes.
246     * The content of the returned <code>NodeList</code> is "live" in the sense
247     * that, for instance, changes to the children of the node object that
248     * it was created from are immediately reflected in the nodes returned by
249     * the <code>NodeList</code> accessors; it is not a static snapshot of the
250     * content of the node. This is true for every <code>NodeList</code>,
251     * including the ones returned by the <code>getElementsByTagName</code>
252     * method.
253     */
254    DOM_NodeList    getChildNodes() const;
255    /**
256     * Gets the first child of this node.
257     *
258     * If there is no such node, this returns <code>null</code>.
259     */
260    DOM_Node        getFirstChild() const;
261
262    /**
263     * Gets the last child of this node.
264     *
265     * If there is no such node, this returns <code>null</code>.
266     */
267    DOM_Node        getLastChild() const;
268
269    /**
270     * Gets the node immediately preceding this node.
271     *
272     * If there is no such node, this returns <code>null</code>.
273     */
274    DOM_Node        getPreviousSibling() const;
275
276    /**
277     * Gets the node immediately following this node.
278     *
279     * If there is no such node, this returns <code>null</code>.
280     */
281    DOM_Node        getNextSibling() const;
282
283    /**
284     * Gets a <code>NamedNodeMap</code> containing the attributes of this node (if it
285     * is an <code>Element</code>) or <code>null</code> otherwise.
286     */
287    DOM_NamedNodeMap  getAttributes() const;
288
289    /**
290     * Gets the <code>DOM_Document</code> object associated with this node.
291     *
292     * This is also
293     * the <code>DOM_Document</code> object used to create new nodes. When this
294     * node is a <code>DOM_Document</code> or a <code>DOM_DocumentType</code>
295     * which is not used with any <code>DOM_Document</code> yet, this is
296     * <code>null</code>.
297     *
298     */
299    DOM_Document      getOwnerDocument() const;
300
301    /**
302      * Return the user data pointer.
303      *
304      * User data allows application programs
305      * to attach extra data to DOM nodes, and can be set using the
306      * function <code>DOM_Node::setUserData(p)</code>.
307      * @return The user data pointer.
308      */
309    void              *getUserData() const;
310
311    //@}
312    /** @name Cloning function. */
313    //@{
314
315    /**
316     * Returns a duplicate of this node.
317     *
318     * This function serves as a generic copy constructor for nodes.
319     *
320     * The duplicate node has no parent (
321     * <code>parentNode</code> returns <code>null</code>.).
322     * <br>Cloning an <code>Element</code> copies all attributes and their
323     * values, including those generated by the  XML processor to represent
324     * defaulted attributes, but this method does not copy any text it contains
325     * unless it is a deep clone, since the text is contained in a child
326     * <code>Text</code> node. Cloning any other type of node simply returns a
327     * copy of this node.
328     * @param deep If <code>true</code>, recursively clone the subtree under the
329     *   specified node; if <code>false</code>, clone only the node itself (and
330     *   its attributes, if it is an <code>Element</code>).
331     * @return The duplicate node.
332     */
333    DOM_Node         cloneNode(bool deep) const;
334
335    //@}
336    /** @name Functions to modify the DOM Node. */
337    //@{
338
339    /**
340     * Inserts the node <code>newChild</code> before the existing child node
341     * <code>refChild</code>.
342     *
343     * If <code>refChild</code> is <code>null</code>,
344     * insert <code>newChild</code> at the end of the list of children.
345     * <br>If <code>newChild</code> is a <code>DocumentFragment</code> object,
346     * all of its children are inserted, in the same order, before
347     * <code>refChild</code>. If the <code>newChild</code> is already in the
348     * tree, it is first removed.  Note that a <code>DOM_Node</code> that
349     * has never been assigned to refer to an actual node is == null.
350     * @param newChild The node to insert.
351     * @param refChild The reference node, i.e., the node before which the new
352     *   node must be inserted.
353     * @return The node being inserted.
354     * @exception DOMException
355     *   HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
356     *   allow children of the type of the <code>newChild</code> node, or if
357     *   the node to insert is one of this node's ancestors.
358     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created
359     *   from a different document than the one that created this node.
360     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node or the node being
361     *   inserted is readonly.
362     *   <br>NOT_FOUND_ERR: Raised if <code>refChild</code> is not a child of
363     *   this node.
364     */
365    DOM_Node               insertBefore(const DOM_Node &newChild,
366                                        const DOM_Node &refChild);
367
368
369    /**
370     * Replaces the child node <code>oldChild</code> with <code>newChild</code>
371     * in the list of children, and returns the <code>oldChild</code> node.
372     *
373     * If <CODE>newChild</CODE> is a <CODE>DOM_DocumentFragment</CODE> object,
374     * <CODE>oldChild</CODE> is replaced by all of the <CODE>DOM_DocumentFragment</CODE>
375     * children, which are inserted in the same order.
376     *
377     * If the <code>newChild</code> is already in the tree, it is first removed.
378     * @param newChild The new node to put in the child list.
379     * @param oldChild The node being replaced in the list.
380     * @return The node replaced.
381     * @exception DOMException
382     *   HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
383     *   allow children of the type of the <code>newChild</code> node, or it
384     *   the node to put in is one of this node's ancestors.
385     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created
386     *   from a different document than the one that created this node.
387     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node or the new node is readonly.
388     *   <br>NOT_FOUND_ERR: Raised if <code>oldChild</code> is not a child of
389     *   this node.
390     */
391    DOM_Node       replaceChild(const DOM_Node &newChild,
392                                const DOM_Node &oldChild);
393    /**
394     * Removes the child node indicated by <code>oldChild</code> from the list
395     * of children, and returns it.
396     *
397     * @param oldChild The node being removed.
398     * @return The node removed.
399     * @exception DOMException
400     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
401     *   <br>NOT_FOUND_ERR: Raised if <code>oldChild</code> is not a child of
402     *   this node.
403     */
404    DOM_Node        removeChild(const DOM_Node &oldChild);
405
406    /**
407     * Adds the node <code>newChild</code> to the end of the list of children of
408     * this node.
409     *
410     * If the <code>newChild</code> is already in the tree, it is
411     * first removed.
412     * @param newChild The node to add.If it is a  <code>DocumentFragment</code>
413     *   object, the entire contents of the document fragment are moved into
414     *   the child list of this node
415     * @return The node added.
416     * @exception DOMException
417     *   HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
418     *   allow children of the type of the <code>newChild</code> node, or if
419     *   the node to append is one of this node's ancestors.
420     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created
421     *   from a different document than the one that created this node.
422     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node or the node being
423     *   appended is readonly.
424     */
425    DOM_Node        appendChild(const DOM_Node &newChild);
426
427    //@}
428    /** @name Query functions. */
429    //@{
430
431    /**
432     *  This is a convenience method to allow easy determination of whether a
433     * node has any children.
434     *
435     * @return  <code>true</code> if the node has any children,
436     *   <code>false</code> if the node has no children.
437     */
438    bool             hasChildNodes() const;
439
440
441    /**
442     * Test whether this node is null.
443     *
444     * This C++ class, <code>DOM_Node<code>
445     * functions much like an object reference to an underlying Node, and
446     * this function tests for that reference being null.  Several DOM
447     * APIs, <code>Node.getNextSibling()</code> for example, can return null, and
448     * this function is used to test for that condition.
449     *
450     * <p>Operator == provides another way to perform this null test on a
451     * DOM_Node.
452     */
453    bool                    isNull() const;
454
455    //@}
456    /** @name Set functions. */
457    //@{
458
459
460    /**
461    * Sets the value of the node.
462    *
463    * Any node which can have a nodeValue (@see getNodeValue) will
464    * also accept requests to set it to a string. The exact response to
465    * this varies from node to node -- Attribute, for example, stores
466    * its values in its children and has to replace them with a new Text
467    * holding the replacement value.
468    *
469    * For most types of Node, value is null and attempting to set it
470    * will throw DOMException(NO_MODIFICATION_ALLOWED_ERR). This will
471    * also be thrown if the node is read-only.
472    */
473    void              setNodeValue(const DOMString &nodeValue);
474
475    /**
476      * Set the user data for a node.
477      *
478      * User data allows application programs
479      * to attach extra data to DOM nodes, and can be retrieved using the
480      * function <code>DOM_Node::getUserData(p)</code>.
481      * <p>
482      * Deletion of the user data remains the responsibility of the
483      * application program; it will not be automatically deleted when
484      * the nodes themselves are reclaimed.
485      *
486      * <p> Because DOM_Node is not designed to be subclassed, userdata
487      * provides an alternative means for extending the the information
488      * kept with nodes by an application program.
489      *
490      * @param p The pointer to be kept with the node.
491      */
492    void              setUserData(void *p);
493
494    //@}
495    /** @name Functions introduced in DOM Level 2. */
496    //@{
497
498    /**
499     * Puts all <CODE>DOM_Text</CODE>
500     * nodes in the full depth of the sub-tree underneath this <CODE>DOM_Node</CODE>,
501     * including attribute nodes, into a "normal" form where only markup (e.g.,
502     * tags, comments, processing instructions, CDATA sections, and entity
503     * references) separates <CODE>DOM_Text</CODE>
504     * nodes, i.e., there are neither adjacent <CODE>DOM_Text</CODE>
505     * nodes nor empty <CODE>DOM_Text</CODE>
506     * nodes. This can be used to ensure that the DOM view of a document is the
507     * same as if it were saved and re-loaded, and is useful when operations
508     * (such as XPointer lookups) that depend on a particular document tree
509     * structure are to be used.
510     * <P><B>Note:</B> In cases where the document contains <CODE>DOM_CDATASections</CODE>,
511     * the normalize operation alone may not be sufficient, since XPointers do
512     * not differentiate between <CODE>DOM_Text</CODE>
513     * nodes and <CODE>DOM_CDATASection</CODE>
514     * nodes.</P>
515     *
516     */
517    void              normalize();
518
519    /**
520     * Tests whether the DOM implementation implements a specific
521     * feature and that feature is supported by this node.
522     *
523     * @param feature The string of the feature to test. This is the same
524     * name as what can be passed to the method <code>hasFeature</code> on
525     * <code>DOM_DOMImplementation</code>.
526     * @param version This is the version number of the feature to test. In
527     * Level 2, version 1, this is the string "2.0". If the version is not
528     * specified, supporting any version of the feature will cause the
529     * method to return <code>true</code>.
530     * @return Returns <code>true</code> if the specified feature is supported
531     * on this node, <code>false</code> otherwise.
532     */
533    bool              isSupported(const DOMString &feature,
534                               const DOMString &version) const;
535
536    /**
537     * Get the <em>namespace URI</em> of
538     * this node, or <code>null</code> if it is unspecified.
539     * <p>
540     * This is not a computed value that is the result of a namespace lookup
541     * based on an examination of the namespace declarations in scope. It is
542     * merely the namespace URI given at creation time.
543     * <p>
544     * For nodes of any type other than <CODE>ELEMENT_NODE</CODE> and
545     * <CODE>ATTRIBUTE_NODE</CODE> and nodes created with a DOM Level 1 method,
546     * such as <CODE>createElement</CODE> from the <CODE>DOM_Document</CODE>
547     * interface, this is always <CODE>null</CODE>.
548     *
549     */
550    DOMString         getNamespaceURI() const;
551
552    /**
553     * Get the <em>namespace prefix</em>
554     * of this node, or <code>null</code> if it is unspecified.
555     *
556     */
557    DOMString         getPrefix() const;
558
559    /**
560     * Returns the local part of the <em>qualified name</em> of this node.
561     * <p>
562     * For nodes created with a DOM Level 1 method, such as
563     * <code>createElement</code> from the <code>DOM_Document</code> interface,
564     * it is null.
565     *
566     */
567    DOMString         getLocalName() const;
568
569    /**
570     * Set the <em>namespace prefix</em> of this node.
571     * <p>
572     * Note that setting this attribute, when permitted, changes
573     * the <CODE>nodeName</CODE> attribute, which holds the <EM>qualified
574     * name</EM>, as well as the <CODE>tagName</CODE> and <CODE>name</CODE>
575     * attributes of the <CODE>DOM_Element</CODE> and <CODE>DOM_Attr</CODE>
576     * interfaces, when applicable.
577     * <p>
578     * Note also that changing the prefix of an
579     * attribute, that is known to have a default value, does not make a new
580     * attribute with the default value and the original prefix appear, since the
581     * <CODE>namespaceURI</CODE> and <CODE>localName</CODE> do not change.
582     *
583     * @param prefix The prefix of this node.
584     * @exception DOMException
585     *   INVALID_CHARACTER_ERR: Raised if the specified prefix contains
586     *                          an illegal character.
587     * <br>
588     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
589     * <br>
590     *   NAMESPACE_ERR: Raised if the specified <CODE>prefix</CODE> is
591     *      malformed, if the <CODE>namespaceURI</CODE> of this node is
592     *      <CODE>null</CODE>, if the specified prefix is "xml" and the
593     *      <CODE>namespaceURI</CODE> of this node is different from
594     *      "http://www.w3.org/XML/1998/namespace", if this node is an attribute
595     *      and the specified prefix is "xmlns" and the
596     *      <CODE>namespaceURI</CODE> of this node is different from
597     *      "http://www.w3.org/2000/xmlns/", or if this node is an attribute and
598     *      the <CODE>qualifiedName</CODE> of this node is "xmlns".
599     */
600    void              setPrefix(const DOMString &prefix);
601
602    /**
603     *  Returns whether this node (if it is an element) has any attributes.
604     * @return <code>true</code> if this node has any attributes,
605     *   <code>false</code> otherwise.
606     */
607    bool              hasAttributes() const;
608
609    //@}
610
611protected:
612    NodeImpl   *fImpl;
613
614    DOM_Node(NodeImpl *);
615
616    friend class DOM_Document;
617    friend class DocumentImpl;
618    friend class TreeWalkerImpl;
619    friend class NodeIteratorImpl;
620    friend class DOM_NamedNodeMap;
621    friend class DOM_NodeList;
622    friend class DOMParser;
623    friend class DOM_Entity;
624    friend class RangeImpl;
625    friend class CharacterDataImpl;
626        friend class XUtil;
627
628};
629
630XERCES_CPP_NAMESPACE_END
631
632#endif
633
Note: See TracBrowser for help on using the repository browser.