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

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

xerces added

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