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

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