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

Revision 188, 19.1 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_Element.hpp,v 1.4 2003/01/03 16:40:13 tng Exp $
59 */
60
61#ifndef DOM_Element_HEADER_GUARD_
62#define DOM_Element_HEADER_GUARD_
63
64#include <xercesc/util/XercesDefs.hpp>
65#include "DOM_Node.hpp"
66
67XERCES_CPP_NAMESPACE_BEGIN
68
69
70class DOM_Attr;
71class DOM_NodeList;
72class ElementImpl;
73
74/**
75 * By far the vast majority of objects (apart from text) that authors
76 * encounter when traversing a document are <code>DOM_Element</code> nodes.
77 *
78 * Assume the following XML document:&lt;elementExample id="demo"&gt;
79 * &lt;subelement1/&gt;
80 * &lt;subelement2&gt;&lt;subsubelement/&gt;&lt;/subelement2&gt;
81 * &lt;/elementExample&gt;
82 * <p>When represented using DOM, the top node is an <code>DOM_Element</code> node
83 * for "elementExample", which contains two child <code>DOM_Element</code> nodes,
84 * one for "subelement1" and one for "subelement2". "subelement1" contains no
85 * child nodes.
86 * <p>Elements may have attributes associated with them; since the
87 * <code>DOM_Element</code> interface inherits from <code>DOM_Node</code>, the generic
88 *  <code>DOM_Node</code> interface method <code>getAttributes</code> may be used
89 * to retrieve the set of all attributes for an element.  There are methods on
90 *  the <code>DOM_Element</code> interface to retrieve either an <code>DOM_Attr</code>
91 *  object by name or an attribute value by name. In XML, where an attribute
92 * value may contain entity references, an <code>DOM_Attr</code> object should be
93 * retrieved to examine the possibly fairly complex sub-tree representing the
94 * attribute value. On the other hand, in HTML, where all attributes have
95 * simple string values, methods to directly access an attribute value can
96 * safely be used as a convenience.
97 */
98
99class CDOM_EXPORT DOM_Element: public DOM_Node {
100private:
101
102public:
103    /** @name Constructors and assignment operator */
104    //@{
105    /**
106    * Default constructor for DOM_Element.  The resulting object does not
107    * refer to an actual Element node; it will compare == to 0, and is similar
108    * to a null object reference variable in Java.  It may subsequently be
109    * assigned to refer to an actual Element node.
110    * <p>
111    * New comment nodes are created by DOM_Document::createElement().
112      *
113      */
114    DOM_Element();
115
116    /**
117      * Copy constructor.  Creates a new <code>DOM_Element</code> that refers to the
118      * same underlying actual element as the original.
119      *
120      * @param other The object to be copied
121      */
122    DOM_Element(const DOM_Element &other);
123
124    /**
125      * Assignment operator.
126      *
127      * @param other The object to be copied.
128      */
129    DOM_Element & operator = (const DOM_Element &other);
130
131    /**
132      * Assignment operator.  This overloaded variant is provided for
133      *   the sole purpose of setting a DOM_Node reference variable to
134      *   zero.  Nulling out a reference variable in this way will decrement
135      *   the reference count on the underlying Node object that the variable
136      *   formerly referenced.  This effect is normally obtained when reference
137      *   variable goes out of scope, but zeroing them can be useful for
138      *   global instances, or for local instances that will remain in scope
139      *   for an extended time,  when the storage belonging to the underlying
140      *   node needs to be reclaimed.
141      *
142      * @param val   Only a value of 0, or null, is allowed.
143      */
144    DOM_Element & operator = (const DOM_NullPtr *val);
145
146    //@}
147    /** @name Destructor. */
148    //@{
149         /**
150      * Destructor.  The object being destroyed is the reference
151      * object, not the underlying Element itself.
152          *
153          */
154    ~DOM_Element();
155    //@}
156    /** @name Getter functions. */
157    //@{
158
159  /**
160   * The name of the element.
161   *
162   * For example, in: &lt;elementExample
163   * id="demo"&gt;  ... &lt;/elementExample&gt; , <code>tagName</code> has
164   * the value <code>"elementExample"</code>. Note that this is
165   * case-preserving in XML, as are all of the operations of the DOM.
166   */
167  DOMString         getTagName() const;
168
169  /**
170   * Retrieves an attribute value by name.
171   *
172   * @param name The name of the attribute to retrieve.
173   * @return The <code>DOM_Attr</code> value as a string, or the empty  string if
174   *   that attribute does not have a specified or default value.
175   */
176  DOMString         getAttribute(const DOMString &name) const;
177
178  /**
179   * Retrieves an <code>DOM_Attr</code> node by name.
180   *
181   * @param name The name (<CODE>nodeName</CODE>) of the attribute to retrieve.
182   * @return The <code>DOM_Attr</code> node with the specified name (<CODE>nodeName</CODE>) or
183   *   <code>null</code> if there is no such attribute.
184   */
185  DOM_Attr        getAttributeNode(const DOMString &name) const;
186
187  /**
188   * Returns a <code>NodeList</code> of all descendant elements with a given
189   * tag name, in the order in which they would be encountered in a preorder
190   * traversal of the <code>DOM_Element</code> tree.
191   *
192   * @param name The name of the tag to match on. The special value "*"
193   *   matches all tags.
194   * @return A list of matching <code>DOM_Element</code> nodes.
195   */
196  DOM_NodeList    getElementsByTagName(const DOMString &name) const;
197
198  //@}
199  /** @name Set functions. */
200  //@{
201
202  /**
203   * Adds a new attribute.
204   *
205   * If an attribute with that name is already present
206   * in the element, its value is changed to be that of the value parameter.
207   * This value is a simple string, it is not parsed as it is being set. So
208   * any markup (such as syntax to be recognized as an entity reference) is
209   * treated as literal text, and needs to be appropriately escaped by the
210   * implementation when it is written out. In order to assign an attribute
211   * value that contains entity references, the user must create an
212   * <code>DOM_Attr</code> node plus any <code>Text</code> and
213   * <code>EntityReference</code> nodes, build the appropriate subtree, and
214   * use <code>setAttributeNode</code> to assign it as the value of an
215   * attribute.
216   * @param name The name of the attribute to create or alter.
217   * @param value Value to set in string form.
218   * @exception DOMException
219   *   INVALID_CHARACTER_ERR: Raised if the specified name contains an
220   *   illegal character.
221   *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
222   */
223   void             setAttribute(const DOMString &name,
224                                 const DOMString &value);
225   /**
226    * Adds a new attribute.
227    *
228    * If an attribute with that name (<CODE>nodeName</CODE>) is already present
229    * in the element, it is replaced by the new one.
230    * @param newAttr The <code>DOM_Attr</code> node to add to the attribute list.
231    * @return If the <code>newAttr</code> attribute replaces an existing
232    *   attribute, the replaced
233    *   <code>DOM_Attr</code> node is returned, otherwise <code>null</code> is
234    *   returned.
235    * @exception DOMException
236    *   WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
237    *   different document than the one that created the element.
238    *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
239    *   <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
240    *   attribute of another <code>DOM_Element</code> object. The DOM user must
241    *   explicitly clone <code>DOM_Attr</code> nodes to re-use them in other
242    *   elements.
243    */
244   DOM_Attr        setAttributeNode(DOM_Attr newAttr);
245
246   //@}
247   /** @name Functions which modify the Element. */
248   //@{
249  /**
250   * Removes the specified attribute node.
251   * If the removed <CODE>DOM_Attr</CODE>
252   *   has a default value it is immediately replaced. The replacing attribute
253   *   has the same namespace URI and local name, as well as the original prefix,
254   *   when applicable.
255   *
256   * @param oldAttr The <code>DOM_Attr</code> node to remove from the attribute
257   *   list.
258   * @return The <code>DOM_Attr</code> node that was removed.
259   * @exception DOMException
260   *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
261   *   <br>NOT_FOUND_ERR: Raised if <code>oldAttr</code> is not an attribute
262   *   of the element.
263   */
264  DOM_Attr        removeAttributeNode(DOM_Attr oldAttr);
265
266  /**
267   * Removes an attribute by name.
268   *
269   * If the removed attribute
270   *   is known to have a default value, an attribute immediately appears
271   *   containing the default value as well as the corresponding namespace URI,
272   *   local name, and prefix when applicable.<BR>To remove an attribute by local
273   *   name and namespace URI, use the <CODE>removeAttributeNS</CODE> method.
274   * @param name The name of the attribute to remove.
275   * @exception DOMException
276   *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
277   */
278  void              removeAttribute(const DOMString &name);
279
280  //@}
281  /** @name Functions introduced in DOM Level 2. */
282  //@{
283
284  /**
285   * Retrieves an attribute value by local name and namespace URI.
286   *
287   * @param namespaceURI The <em>namespace URI</em> of
288   *    the attribute to retrieve.
289   * @param localName The <em>local name</em> of the
290   *    attribute to retrieve.
291   * @return The <code>DOM_Attr</code> value as a string, or an <CODE>null</CODE> if
292   *    that attribute does not have a specified or default value.
293   */
294  DOMString         getAttributeNS(const DOMString &namespaceURI,
295        const DOMString &localName) const;
296
297  /**
298   * Adds a new attribute. If an attribute with the same
299   * local name and namespace URI is already present on the element, its prefix
300   * is changed to be the prefix part of the <CODE>qualifiedName</CODE>, and
301   * its value is changed to be the <CODE>value</CODE> parameter. This value is
302   * a simple string, it is not parsed as it is being set. So any markup (such
303   * as syntax to be recognized as an entity reference) is treated as literal
304   * text, and needs to be appropriately escaped by the implementation when it
305   * is written out. In order to assign an attribute value that contains entity
306   * references, the user must create an <CODE>DOM_Attr</CODE>
307   * node plus any <CODE>DOM_Text</CODE> and <CODE>DOM_EntityReference</CODE>
308   * nodes, build the appropriate subtree, and use
309   * <CODE>setAttributeNodeNS</CODE> or <CODE>setAttributeNode</CODE> to assign
310   * it as the value of an attribute.
311   *
312   * @param namespaceURI The <em>namespace URI</em> of
313   *    the attribute to create or alter.
314   * @param qualifiedName The <em>qualified name</em> of the
315   *    attribute to create or alter.
316   * @param value The value to set in string form.
317   * @exception DOMException
318   *   INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an
319   *   illegal character.
320   *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
321   * <br>
322   *   NAMESPACE_ERR: Raised if the <CODE>qualifiedName</CODE> is
323   *        malformed, if the <CODE>qualifiedName</CODE> has a prefix and the
324   *        <CODE>namespaceURI</CODE> is <CODE>null</CODE> or an empty string,
325   *        if the <CODE>qualifiedName</CODE> has a prefix that is "xml" and the
326   *        <CODE>namespaceURI</CODE> is different from
327   *        "http://www.w3.org/XML/1998/namespace", if the
328   *        <CODE>qualifiedName</CODE> has a prefix that is "xmlns" and the
329   *        <CODE>namespaceURI</CODE> is different from
330   *        "http://www.w3.org/2000/xmlns/", or if the
331   *        <CODE>qualifiedName</CODE> is "xmlns" and the
332   *        <CODE>namespaceURI</CODE> is different from
333   *        "http://www.w3.org/2000/xmlns/".
334   */
335   void             setAttributeNS(const DOMString &namespaceURI,
336        const DOMString &qualifiedName, const DOMString &value);
337
338  /**
339   * Removes an attribute by local name and namespace URI. If the
340   * removed attribute has a default value it is immediately replaced.
341   * The replacing attribute has the same namespace URI and local name, as well as
342   * the original prefix.
343   *
344   * @param namespaceURI The <em>namespace URI</em> of
345   *    the attribute to remove.
346   * @param localName The <em>local name</em> of the
347   *    attribute to remove.
348   * @exception DOMException
349   *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
350   */
351  void              removeAttributeNS(const DOMString &namespaceURI,
352        const DOMString &localName);
353
354  /**
355   * Retrieves an <code>DOM_Attr</code> node by local name and namespace URI.
356   *
357   * @param namespaceURI The <em>namespace URI</em> of
358   *    the attribute to retrieve.
359   * @param localName The <em>local name</em> of the
360   *    attribute to retrieve.
361   * @return The <code>DOM_Attr</code> node with the specified attribute local
362   *    name and namespace URI or <code>null</code> if there is no such attribute.
363   */
364  DOM_Attr        getAttributeNodeNS(const DOMString &namespaceURI,
365        const DOMString &localName) const;
366
367   /**
368    * Adds a new attribute.
369    *
370    * If an attribute with that local name and namespace URI is already present
371    * in the element, it is replaced by the new one.
372    *
373    * @param newAttr The <code>DOM_Attr</code> node to add to the attribute list.
374    * @return If the <code>newAttr</code> attribute replaces an existing
375    *    attribute with the same <em>local name</em> and <em>namespace URI</em>,
376    *    the replaced <code>DOM_Attr</code> node is
377    *    returned, otherwise <code>null</code> is returned.
378    * @exception DOMException
379    *   WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
380    *   different document than the one that created the element.
381    *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
382    *   <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
383    *   attribute of another <code>DOM_Element</code> object. The DOM user must
384    *   explicitly clone <code>DOM_Attr</code> nodes to re-use them in other
385    *   elements.
386    */
387   DOM_Attr        setAttributeNodeNS(DOM_Attr newAttr);
388
389  /**
390   * Returns a <code>DOM_NodeList</code> of all the <code>DOM_Element</code>s
391   * with a given local name and namespace URI in the order in which they
392   * would be encountered in a preorder traversal of the
393   * <code>DOM_Document</code> tree, starting from this node.
394   *
395   * @param namespaceURI The <em>namespace URI</em> of
396   *    the elements to match on. The special value "*" matches all
397   *    namespaces.
398   * @param localName The <em>local name</em> of the
399   *    elements to match on. The special value "*" matches all local names.
400   * @return A new <code>DOM_NodeList</code> object containing all the matched
401   *    <code>DOM_Element</code>s.
402   */
403  DOM_NodeList    getElementsByTagNameNS(const DOMString &namespaceURI,
404        const DOMString &localName) const;
405
406    /**
407     *  Returns whether this node (if it is an element) has any attributes.
408     * @return <code>true</code> if this node has any attributes,
409     *   <code>false</code> otherwise.
410     */
411    bool         hasAttributes() const;
412
413    /**
414     * Returns <code>true</code> when an attribute with a given name is
415     * specified on this element or has a default value, <code>false</code>
416     * otherwise.
417     * @param name The name of the attribute to look for.
418     * @return <code>true</code> if an attribute with the given name is
419     *   specified on this element or has a default value, <code>false</code>
420     *    otherwise.
421     */
422    bool         hasAttribute(const DOMString &name) const;
423
424    /**
425     * Returns <code>true</code> when an attribute with a given local name and
426     * namespace URI is specified on this element or has a default value,
427     * <code>false</code> otherwise. HTML-only DOM implementations do not
428     * need to implement this method.
429     * @param namespaceURI The namespace URI of the attribute to look for.
430     * @param localName The local name of the attribute to look for.
431     * @return <code>true</code> if an attribute with the given local name
432     *   and namespace URI is specified or has a default value on this
433     *   element, <code>false</code> otherwise.
434     * @since DOM Level 2
435     */
436    bool         hasAttributeNS(const DOMString &namespaceURI,
437                                const DOMString &localName) const;
438
439  //@}
440
441  protected:
442     DOM_Element(ElementImpl *impl);
443
444     friend class DOM_Document;
445     friend class DOM_Attr;
446};
447
448XERCES_CPP_NAMESPACE_END
449
450#endif
451
452
Note: See TracBrowser for help on using the repository browser.