source: NonGTP/Xerces/xercesc/dom/DOMElement.hpp @ 188

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

added xercesc to support

Line 
1#ifndef DOMElement_HEADER_GUARD_
2#define DOMElement_HEADER_GUARD_
3
4/*
5 * The Apache Software License, Version 1.1
6 *
7 * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
8 * reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in
19 *    the documentation and/or other materials provided with the
20 *    distribution.
21 *
22 * 3. The end-user documentation included with the redistribution,
23 *    if any, must include the following acknowledgment:
24 *       "This product includes software developed by the
25 *        Apache Software Foundation (http://www.apache.org/)."
26 *    Alternately, this acknowledgment may appear in the software itself,
27 *    if and wherever such third-party acknowledgments normally appear.
28 *
29 * 4. The names "Xerces" and "Apache Software Foundation" must
30 *    not be used to endorse or promote products derived from this
31 *    software without prior written permission. For written
32 *    permission, please contact apache\@apache.org.
33 *
34 * 5. Products derived from this software may not be called "Apache",
35 *    nor may "Apache" appear in their name, without prior written
36 *    permission of the Apache Software Foundation.
37 *
38 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
39 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
45 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
46 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
48 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49 * SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This software consists of voluntary contributions made by many
53 * individuals on behalf of the Apache Software Foundation, and was
54 * originally based on software copyright (c) 2001, International
55 * Business Machines, Inc., http://www.ibm.com .  For more information
56 * on the Apache Software Foundation, please see
57 * <http://www.apache.org/>.
58 */
59
60/*
61 * $Id: DOMElement.hpp,v 1.9 2003/03/07 19:59:03 tng Exp $
62 */
63
64#include <xercesc/util/XercesDefs.hpp>
65#include "DOMNode.hpp"
66
67XERCES_CPP_NAMESPACE_BEGIN
68
69
70class DOMAttr;
71class DOMNodeList;
72class DOMTypeInfo;
73
74
75/**
76 * By far the vast majority of objects (apart from text) that authors
77 * encounter when traversing a document are <code>DOMElement</code> nodes.
78 *
79 * Assume the following XML document:&lt;elementExample id="demo"&gt;
80 * &lt;subelement1/&gt;
81 * &lt;subelement2&gt;&lt;subsubelement/&gt;&lt;/subelement2&gt;
82 * &lt;/elementExample&gt;
83 * <p>When represented using DOM, the top node is an <code>DOMElement</code> node
84 * for "elementExample", which contains two child <code>DOMElement</code> nodes,
85 * one for "subelement1" and one for "subelement2". "subelement1" contains no
86 * child nodes.
87 * <p>Elements may have attributes associated with them; since the
88 * <code>DOMElement</code> interface inherits from <code>DOMNode</code>, the generic
89 *  <code>DOMNode</code> interface method <code>getAttributes</code> may be used
90 * to retrieve the set of all attributes for an element.  There are methods on
91 *  the <code>DOMElement</code> interface to retrieve either an <code>DOMAttr</code>
92 *  object by name or an attribute value by name. In XML, where an attribute
93 * value may contain entity references, an <code>DOMAttr</code> object should be
94 * retrieved to examine the possibly fairly complex sub-tree representing the
95 * attribute value. On the other hand, in HTML, where all attributes have
96 * simple string values, methods to directly access an attribute value can
97 * safely be used as a convenience.
98 *
99 * @since DOM Level 1
100 */
101
102class CDOM_EXPORT DOMElement: public DOMNode {
103protected:
104    // -----------------------------------------------------------------------
105    //  Hidden constructors
106    // -----------------------------------------------------------------------
107    /** @name Hidden constructors */
108    //@{   
109    DOMElement() {};
110    //@}
111   
112private:
113    // -----------------------------------------------------------------------
114    // Unimplemented constructors and operators
115    // -----------------------------------------------------------------------
116    /** @name Unimplemented constructors and operators */
117    //@{
118    DOMElement(const DOMElement &);
119    DOMElement & operator = (const DOMElement &);
120    //@}
121
122public:
123    // -----------------------------------------------------------------------
124    //  All constructors are hidden, just the destructor is available
125    // -----------------------------------------------------------------------
126    /** @name Destructor */
127    //@{
128    /**
129     * Destructor
130     *
131     */
132    virtual ~DOMElement() {};
133    //@}
134
135    // -----------------------------------------------------------------------
136    //  Virtual DOMElement interface
137    // -----------------------------------------------------------------------
138    /** @name Functions introduced in DOM Level 1 */
139    //@{
140    // -----------------------------------------------------------------------
141    //  Getter methods
142    // -----------------------------------------------------------------------
143    /**
144     * The name of the element.
145     *
146     * For example, in: &lt;elementExample
147     * id="demo"&gt;  ... &lt;/elementExample&gt; , <code>tagName</code> has
148     * the value <code>"elementExample"</code>. Note that this is
149     * case-preserving in XML, as are all of the operations of the DOM.
150     * @since DOM Level 1
151     */
152    virtual const XMLCh *         getTagName() const = 0;
153
154    /**
155     * Retrieves an attribute value by name.
156     *
157     * @param name The name of the attribute to retrieve.
158     * @return The <code>DOMAttr</code> value as a string, or the empty  string if
159     *   that attribute does not have a specified or default value.
160     * @since DOM Level 1
161     */
162    virtual const XMLCh *         getAttribute(const XMLCh *name) const = 0;
163
164    /**
165     * Retrieves an <code>DOMAttr</code> node by name.
166     *
167     * @param name The name (<CODE>nodeName</CODE>) of the attribute to retrieve.
168     * @return The <code>DOMAttr</code> node with the specified name (<CODE>nodeName</CODE>) or
169     *   <code>null</code> if there is no such attribute.
170     * @since DOM Level 1
171     */
172    virtual DOMAttr       * getAttributeNode(const XMLCh *name) const = 0;
173
174    /**
175     * Returns a <code>DOMNodeList</code> of all descendant elements with a given
176     * tag name, in the order in which they would be encountered in a preorder
177     * traversal of the <code>DOMElement</code> tree.
178     *
179     * @param name The name of the tag to match on. The special value "*"
180     *   matches all tags.
181     * @return A list of matching <code>DOMElement</code> nodes.
182     * @since DOM Level 1
183     */
184    virtual DOMNodeList   * getElementsByTagName(const XMLCh *name) const = 0;
185
186    // -----------------------------------------------------------------------
187    //  Setter methods
188    // -----------------------------------------------------------------------
189    /**
190     * Adds a new attribute.
191     *
192     * If an attribute with that name is already present
193     * in the element, its value is changed to be that of the value parameter.
194     * This value is a simple string, it is not parsed as it is being set. So
195     * any markup (such as syntax to be recognized as an entity reference) is
196     * treated as literal text, and needs to be appropriately escaped by the
197     * implementation when it is written out. In order to assign an attribute
198     * value that contains entity references, the user must create an
199     * <code>DOMAttr</code> node plus any <code>DOMText</code> and
200     * <code>DOMEntityReference</code> nodes, build the appropriate subtree, and
201     * use <code>setAttributeNode</code> to assign it as the value of an
202     * attribute.
203     * @param name The name of the attribute to create or alter.
204     * @param value Value to set in string form.
205     * @exception DOMException
206     *   INVALID_CHARACTER_ERR: Raised if the specified name contains an
207     *   illegal character.
208     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
209     * @since DOM Level 1
210     */
211    virtual void             setAttribute(const XMLCh *name,
212                                  const XMLCh *value) = 0;
213    /**
214     * Adds a new attribute.
215     *
216     * If an attribute with that name (<CODE>nodeName</CODE>) is already present
217     * in the element, it is replaced by the new one.
218     * @param newAttr The <code>DOMAttr</code> node to add to the attribute list.
219     * @return If the <code>newAttr</code> attribute replaces an existing
220     *   attribute, the replaced
221     *   <code>DOMAttr</code> node is returned, otherwise <code>null</code> is
222     *   returned.
223     * @exception DOMException
224     *   WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
225     *   different document than the one that created the element.
226     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
227     *   <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
228     *   attribute of another <code>DOMElement</code> object. The DOM user must
229     *   explicitly clone <code>DOMAttr</code> nodes to re-use them in other
230     *   elements.
231     * @since DOM Level 1
232     */
233    virtual DOMAttr       * setAttributeNode(DOMAttr *newAttr) = 0;
234
235    /**
236     * Removes the specified attribute node.
237     * If the removed <CODE>DOMAttr</CODE>
238     *   has a default value it is immediately replaced. The replacing attribute
239     *   has the same namespace URI and local name, as well as the original prefix,
240     *   when applicable.
241     *
242     * @param oldAttr The <code>DOMAttr</code> node to remove from the attribute
243     *   list.
244     * @return The <code>DOMAttr</code> node that was removed.
245     * @exception DOMException
246     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
247     *   <br>NOT_FOUND_ERR: Raised if <code>oldAttr</code> is not an attribute
248     *   of the element.
249     * @since DOM Level 1
250     */
251    virtual DOMAttr       * removeAttributeNode(DOMAttr *oldAttr) = 0;
252
253    /**
254     * Removes an attribute by name.
255     *
256     * If the removed attribute
257     *   is known to have a default value, an attribute immediately appears
258     *   containing the default value as well as the corresponding namespace URI,
259     *   local name, and prefix when applicable.<BR>To remove an attribute by local
260     *   name and namespace URI, use the <CODE>removeAttributeNS</CODE> method.
261     * @param name The name of the attribute to remove.
262     * @exception DOMException
263     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
264     * @since DOM Level 1
265     */
266    virtual void              removeAttribute(const XMLCh *name) = 0;
267    //@}
268
269    /** @name Functions introduced in DOM Level 2. */
270    //@{
271    /**
272     * Retrieves an attribute value by local name and namespace URI.
273     *
274     * @param namespaceURI The <em>namespace URI</em> of
275     *    the attribute to retrieve.
276     * @param localName The <em>local name</em> of the
277     *    attribute to retrieve.
278     * @return The <code>DOMAttr</code> value as a string, or an <CODE>null</CODE> if
279     *    that attribute does not have a specified or default value.
280     * @since DOM Level 2
281     */
282    virtual const XMLCh *         getAttributeNS(const XMLCh *namespaceURI,
283                                                 const XMLCh *localName) const = 0;
284
285    /**
286     * Adds a new attribute. If an attribute with the same
287     * local name and namespace URI is already present on the element, its prefix
288     * is changed to be the prefix part of the <CODE>qualifiedName</CODE>, and
289     * its value is changed to be the <CODE>value</CODE> parameter. This value is
290     * a simple string, it is not parsed as it is being set. So any markup (such
291     * as syntax to be recognized as an entity reference) is treated as literal
292     * text, and needs to be appropriately escaped by the implementation when it
293     * is written out. In order to assign an attribute value that contains entity
294     * references, the user must create an <CODE>DOMAttr</CODE>
295     * node plus any <CODE>DOMText</CODE> and <CODE>DOMEntityReference</CODE>
296     * nodes, build the appropriate subtree, and use
297     * <CODE>setAttributeNodeNS</CODE> or <CODE>setAttributeNode</CODE> to assign
298     * it as the value of an attribute.
299     *
300     * @param namespaceURI The <em>namespace URI</em> of
301     *    the attribute to create or alter.
302     * @param qualifiedName The <em>qualified name</em> of the
303     *    attribute to create or alter.
304     * @param value The value to set in string form.
305     * @exception DOMException
306     *   INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an
307     *   illegal character.
308     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
309     * <br>
310     *   NAMESPACE_ERR: Raised if the <CODE>qualifiedName</CODE> is
311     *        malformed, if the <CODE>qualifiedName</CODE> has a prefix and the
312     *        <CODE>namespaceURI</CODE> is <CODE>null</CODE> or an empty string,
313     *        if the <CODE>qualifiedName</CODE> has a prefix that is "xml" and the
314     *        <CODE>namespaceURI</CODE> is different from
315     *        "http://www.w3.org/XML/1998/namespace", if the
316     *        <CODE>qualifiedName</CODE> has a prefix that is "xmlns" and the
317     *        <CODE>namespaceURI</CODE> is different from
318     *        "http://www.w3.org/2000/xmlns/", or if the
319     *        <CODE>qualifiedName</CODE> is "xmlns" and the
320     *        <CODE>namespaceURI</CODE> is different from
321     *        "http://www.w3.org/2000/xmlns/".
322     * @since DOM Level 2
323     */
324    virtual void             setAttributeNS(const XMLCh *namespaceURI,
325                                            const XMLCh *qualifiedName, const XMLCh *value) = 0;
326
327    /**
328     * Removes an attribute by local name and namespace URI. If the
329     * removed attribute has a default value it is immediately replaced.
330     * The replacing attribute has the same namespace URI and local name, as well as
331     * the original prefix.
332     *
333     * @param namespaceURI The <em>namespace URI</em> of
334     *    the attribute to remove.
335     * @param localName The <em>local name</em> of the
336     *    attribute to remove.
337     * @exception DOMException
338     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
339     * @since DOM Level 2
340     */
341    virtual void              removeAttributeNS(const XMLCh *namespaceURI,
342                                                const XMLCh *localName) = 0;
343
344    /**
345     * Retrieves an <code>DOMAttr</code> node by local name and namespace URI.
346     *
347     * @param namespaceURI The <em>namespace URI</em> of
348     *    the attribute to retrieve.
349     * @param localName The <em>local name</em> of the
350     *    attribute to retrieve.
351     * @return The <code>DOMAttr</code> node with the specified attribute local
352     *    name and namespace URI or <code>null</code> if there is no such attribute.
353     * @since DOM Level 2
354     */
355    virtual DOMAttr      *  getAttributeNodeNS(const XMLCh *namespaceURI,
356                                               const XMLCh *localName) const = 0;
357
358    /**
359     * Adds a new attribute.
360     *
361     * If an attribute with that local name and namespace URI is already present
362     * in the element, it is replaced by the new one.
363     *
364     * @param newAttr The <code>DOMAttr</code> node to add to the attribute list.
365     * @return If the <code>newAttr</code> attribute replaces an existing
366     *    attribute with the same <em>local name</em> and <em>namespace URI</em>,
367     *    the replaced <code>DOMAttr</code> node is
368     *    returned, otherwise <code>null</code> is returned.
369     * @exception DOMException
370     *   WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
371     *   different document than the one that created the element.
372     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
373     *   <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
374     *   attribute of another <code>DOMElement</code> object. The DOM user must
375     *   explicitly clone <code>DOMAttr</code> nodes to re-use them in other
376     *   elements.
377     * @since DOM Level 2
378     */
379    virtual DOMAttr      *  setAttributeNodeNS(DOMAttr *newAttr) = 0;
380
381    /**
382     * Returns a <code>DOMNodeList</code> of all the <code>DOMElement</code>s
383     * with a given local name and namespace URI in the order in which they
384     * would be encountered in a preorder traversal of the
385     * <code>DOMDocument</code> tree, starting from this node.
386     *
387     * @param namespaceURI The <em>namespace URI</em> of
388     *    the elements to match on. The special value "*" matches all
389     *    namespaces.
390     * @param localName The <em>local name</em> of the
391     *    elements to match on. The special value "*" matches all local names.
392     * @return A new <code>DOMNodeList</code> object containing all the matched
393     *    <code>DOMElement</code>s.
394     * @since DOM Level 2
395     */
396    virtual DOMNodeList   * getElementsByTagNameNS(const XMLCh *namespaceURI,
397                                                   const XMLCh *localName) const = 0;
398
399    /**
400     * Returns <code>true</code> when an attribute with a given name is
401     * specified on this element or has a default value, <code>false</code>
402     * otherwise.
403     * @param name The name of the attribute to look for.
404     * @return <code>true</code> if an attribute with the given name is
405     *   specified on this element or has a default value, <code>false</code>
406     *    otherwise.
407     * @since DOM Level 2
408     */
409    virtual bool         hasAttribute(const XMLCh *name) const = 0;
410
411    /**
412     * Returns <code>true</code> when an attribute with a given local name and
413     * namespace URI is specified on this element or has a default value,
414     * <code>false</code> otherwise. HTML-only DOM implementations do not
415     * need to implement this method.
416     * @param namespaceURI The namespace URI of the attribute to look for.
417     * @param localName The local name of the attribute to look for.
418     * @return <code>true</code> if an attribute with the given local name
419     *   and namespace URI is specified or has a default value on this
420     *   element, <code>false</code> otherwise.
421     * @since DOM Level 2
422     */
423    virtual bool         hasAttributeNS(const XMLCh *namespaceURI,
424                                        const XMLCh *localName) const = 0;
425    //@}
426
427    /** @name Functions introduced in DOM Level 3 */
428    //@{
429
430    /**
431     * Declares the <code>DOMAttr</code> specified by name to be of type ID. If the
432     * value of the specified <code>DOMAttr</code> is unique then this element node
433     * can later be retrieved using getElementById on Document. Note, however,
434     * that this simply affects this node and does not change any grammar that
435     * may be in use.
436     * To specify an <code>DOMAttr</code> by local name and namespace URI, use the
437     * setIdAttributeNS method.
438     * @param name The name of the <code>DOMAttr</code>.
439     * @exception DOMException
440     *    NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
441     *    <br />NOT_FOUND_ERR: Raised if the specified node is not an <code>DOMAttr</code>
442     * of this element.
443     *
444     * <p><b>"Experimental - subject to change"</b></p>
445     *
446     * @since DOM Level 3
447     */
448    virtual void setIdAttribute(const XMLCh* name) = 0;
449
450
451    /**
452     * Declares the <code>DOMAttr</code> specified by local name and namespace
453     * URI to be of type ID. If the value of the specified <code>DOMAttr</code>
454     * is unique then this <code>DOMElement</code> node can later be retrieved
455     * using getElementById on <code>DOMDocument</code>. Note, however, that
456     * this simply affects this node and does not change any grammar that may
457     * be in use.
458     * @param namespaceURI The namespace URI of the <code>DOMAttr</code>.
459     * @param localName The local name of the <code>DOMAttr</code>.
460     * @exception  DOMException
461     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
462     *   <br />NOT_FOUND_ERR: Raised if the specified node is not an <code>DOMAttr</code> of this element.
463     *
464     * <p><b>"Experimental - subject to change"</b></p>
465     *
466     * @since DOM Level 3
467     */
468    virtual void setIdAttributeNS(const XMLCh* namespaceURI, const XMLCh* localName) = 0;
469
470
471
472    /**
473     * Declares the <code>DOMAttr</code> specified by node to be of type ID.
474     * If the value of the specified <code>DOMAttr</code> is unique then this
475     * <code>DOMElement</code> node can later be retrieved using getElementById
476     * on <code>DOMDocument</code>. Note, however, that this simply affects this
477     * node and does not change any grammar that may be in use.
478     * @param idAttr The <code>DOMAttr</code> node.
479     * @exception  DOMException
480     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
481     *   <br />NOT_FOUND_ERR: Raised if the specified node is not an <code>DOMAttr</code> of this element.
482     *
483     * <p><b>"Experimental - subject to change"</b></p>
484     *
485     * @since DOM Level 3
486     */
487    virtual void setIdAttributeNode(const DOMAttr *idAttr) = 0;
488
489
490
491    /**
492     * Returns the type information associated with this element.
493     *
494     * <p><b>"Experimental - subject to change"</b></p>
495     *
496     * @return the <code>DOMTypeInfo</code> associated with this element
497     * @since DOM level 3
498     */
499    virtual const DOMTypeInfo* getTypeInfo() const = 0;
500
501    //@}
502
503};
504
505XERCES_CPP_NAMESPACE_END
506
507#endif
508
509
510
Note: See TracBrowser for help on using the repository browser.