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

Revision 2674, 20.2 KB checked in by mattausch, 16 years ago (diff)
Line 
1#ifndef DOMElement_HEADER_GUARD_
2#define DOMElement_HEADER_GUARD_
3
4/*
5 * Licensed to the Apache Software Foundation (ASF) under one or more
6 * contributor license agreements.  See the NOTICE file distributed with
7 * this work for additional information regarding copyright ownership.
8 * The ASF licenses this file to You under the Apache License, Version 2.0
9 * (the "License"); you may not use this file except in compliance with
10 * the License.  You may obtain a copy of the License at
11 *
12 *      http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21/*
22 * $Id: DOMElement.hpp 568078 2007-08-21 11:43:25Z amassari $
23 */
24
25#include <xercesc/util/XercesDefs.hpp>
26#include <xercesc/dom/DOMNode.hpp>
27
28XERCES_CPP_NAMESPACE_BEGIN
29
30
31class DOMAttr;
32class DOMNodeList;
33class DOMTypeInfo;
34
35
36/**
37 * By far the vast majority of objects (apart from text) that authors
38 * encounter when traversing a document are <code>DOMElement</code> nodes.
39 *
40 * Assume the following XML document:&lt;elementExample id="demo"&gt;
41 * &lt;subelement1/&gt;
42 * &lt;subelement2&gt;&lt;subsubelement/&gt;&lt;/subelement2&gt;
43 * &lt;/elementExample&gt;
44 * <p>When represented using DOM, the top node is an <code>DOMElement</code> node
45 * for "elementExample", which contains two child <code>DOMElement</code> nodes,
46 * one for "subelement1" and one for "subelement2". "subelement1" contains no
47 * child nodes.
48 * <p>Elements may have attributes associated with them; since the
49 * <code>DOMElement</code> interface inherits from <code>DOMNode</code>, the generic
50 *  <code>DOMNode</code> interface method <code>getAttributes</code> may be used
51 * to retrieve the set of all attributes for an element.  There are methods on
52 *  the <code>DOMElement</code> interface to retrieve either an <code>DOMAttr</code>
53 *  object by name or an attribute value by name. In XML, where an attribute
54 * value may contain entity references, an <code>DOMAttr</code> object should be
55 * retrieved to examine the possibly fairly complex sub-tree representing the
56 * attribute value. On the other hand, in HTML, where all attributes have
57 * simple string values, methods to directly access an attribute value can
58 * safely be used as a convenience.
59 *
60 * @since DOM Level 1
61 */
62
63class CDOM_EXPORT DOMElement: public DOMNode {
64protected:
65    // -----------------------------------------------------------------------
66    //  Hidden constructors
67    // -----------------------------------------------------------------------
68    /** @name Hidden constructors */
69    //@{   
70    DOMElement() {}
71    DOMElement(const DOMElement &other) : DOMNode(other) {}
72    //@}
73   
74private:
75    // -----------------------------------------------------------------------
76    // Unimplemented constructors and operators
77    // -----------------------------------------------------------------------
78    /** @name Unimplemented operators */
79    //@{
80    DOMElement & operator = (const DOMElement &);
81    //@}
82
83public:
84    // -----------------------------------------------------------------------
85    //  All constructors are hidden, just the destructor is available
86    // -----------------------------------------------------------------------
87    /** @name Destructor */
88    //@{
89    /**
90     * Destructor
91     *
92     */
93    virtual ~DOMElement() {};
94    //@}
95
96    // -----------------------------------------------------------------------
97    //  Virtual DOMElement interface
98    // -----------------------------------------------------------------------
99    /** @name Functions introduced in DOM Level 1 */
100    //@{
101    // -----------------------------------------------------------------------
102    //  Getter methods
103    // -----------------------------------------------------------------------
104    /**
105     * The name of the element.
106     *
107     * For example, in: &lt;elementExample
108     * id="demo"&gt;  ... &lt;/elementExample&gt; , <code>tagName</code> has
109     * the value <code>"elementExample"</code>. Note that this is
110     * case-preserving in XML, as are all of the operations of the DOM.
111     * @since DOM Level 1
112     */
113    virtual const XMLCh *         getTagName() const = 0;
114
115    /**
116     * Retrieves an attribute value by name.
117     *
118     * @param name The name of the attribute to retrieve.
119     * @return The <code>DOMAttr</code> value as a string, or the empty  string if
120     *   that attribute does not have a specified or default value.
121     * @since DOM Level 1
122     */
123    virtual const XMLCh *         getAttribute(const XMLCh *name) const = 0;
124
125    /**
126     * Retrieves an <code>DOMAttr</code> node by name.
127     *
128     * @param name The name (<CODE>nodeName</CODE>) of the attribute to retrieve.
129     * @return The <code>DOMAttr</code> node with the specified name (<CODE>nodeName</CODE>) or
130     *   <code>null</code> if there is no such attribute.
131     * @since DOM Level 1
132     */
133    virtual DOMAttr       * getAttributeNode(const XMLCh *name) const = 0;
134
135    /**
136     * Returns a <code>DOMNodeList</code> of all descendant elements with a given
137     * tag name, in the order in which they would be encountered in a preorder
138     * traversal of the <code>DOMElement</code> tree.
139     *
140     * @param name The name of the tag to match on. The special value "*"
141     *   matches all tags.
142     * @return A list of matching <code>DOMElement</code> nodes.
143     * @since DOM Level 1
144     */
145    virtual DOMNodeList   * getElementsByTagName(const XMLCh *name) const = 0;
146
147    // -----------------------------------------------------------------------
148    //  Setter methods
149    // -----------------------------------------------------------------------
150    /**
151     * Adds a new attribute.
152     *
153     * If an attribute with that name is already present
154     * in the element, its value is changed to be that of the value parameter.
155     * This value is a simple string, it is not parsed as it is being set. So
156     * any markup (such as syntax to be recognized as an entity reference) is
157     * treated as literal text, and needs to be appropriately escaped by the
158     * implementation when it is written out. In order to assign an attribute
159     * value that contains entity references, the user must create an
160     * <code>DOMAttr</code> node plus any <code>DOMText</code> and
161     * <code>DOMEntityReference</code> nodes, build the appropriate subtree, and
162     * use <code>setAttributeNode</code> to assign it as the value of an
163     * attribute.
164     * @param name The name of the attribute to create or alter.
165     * @param value Value to set in string form.
166     * @exception DOMException
167     *   INVALID_CHARACTER_ERR: Raised if the specified name contains an
168     *   illegal character.
169     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
170     * @since DOM Level 1
171     */
172    virtual void             setAttribute(const XMLCh *name,
173                                  const XMLCh *value) = 0;
174    /**
175     * Adds a new attribute.
176     *
177     * If an attribute with that name (<CODE>nodeName</CODE>) is already present
178     * in the element, it is replaced by the new one.
179     * @param newAttr The <code>DOMAttr</code> node to add to the attribute list.
180     * @return If the <code>newAttr</code> attribute replaces an existing
181     *   attribute, the replaced
182     *   <code>DOMAttr</code> node is returned, otherwise <code>null</code> is
183     *   returned.
184     * @exception DOMException
185     *   WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
186     *   different document than the one that created the element.
187     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
188     *   <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
189     *   attribute of another <code>DOMElement</code> object. The DOM user must
190     *   explicitly clone <code>DOMAttr</code> nodes to re-use them in other
191     *   elements.
192     * @since DOM Level 1
193     */
194    virtual DOMAttr       * setAttributeNode(DOMAttr *newAttr) = 0;
195
196    /**
197     * Removes the specified attribute node.
198     * If the removed <CODE>DOMAttr</CODE>
199     *   has a default value it is immediately replaced. The replacing attribute
200     *   has the same namespace URI and local name, as well as the original prefix,
201     *   when applicable.
202     *
203     * @param oldAttr The <code>DOMAttr</code> node to remove from the attribute
204     *   list.
205     * @return The <code>DOMAttr</code> node that was removed.
206     * @exception DOMException
207     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
208     *   <br>NOT_FOUND_ERR: Raised if <code>oldAttr</code> is not an attribute
209     *   of the element.
210     * @since DOM Level 1
211     */
212    virtual DOMAttr       * removeAttributeNode(DOMAttr *oldAttr) = 0;
213
214    /**
215     * Removes an attribute by name.
216     *
217     * If the removed attribute
218     *   is known to have a default value, an attribute immediately appears
219     *   containing the default value as well as the corresponding namespace URI,
220     *   local name, and prefix when applicable.<BR>To remove an attribute by local
221     *   name and namespace URI, use the <CODE>removeAttributeNS</CODE> method.
222     * @param name The name of the attribute to remove.
223     * @exception DOMException
224     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
225     * @since DOM Level 1
226     */
227    virtual void              removeAttribute(const XMLCh *name) = 0;
228    //@}
229
230    /** @name Functions introduced in DOM Level 2. */
231    //@{
232    /**
233     * Retrieves an attribute value by local name and namespace URI.
234     *
235     * @param namespaceURI The <em>namespace URI</em> of
236     *    the attribute to retrieve.
237     * @param localName The <em>local name</em> of the
238     *    attribute to retrieve.
239     * @return The <code>DOMAttr</code> value as a string, or an <CODE>null</CODE> if
240     *    that attribute does not have a specified or default value.
241     * @since DOM Level 2
242     */
243    virtual const XMLCh *         getAttributeNS(const XMLCh *namespaceURI,
244                                                 const XMLCh *localName) const = 0;
245
246    /**
247     * Adds a new attribute. If an attribute with the same
248     * local name and namespace URI is already present on the element, its prefix
249     * is changed to be the prefix part of the <CODE>qualifiedName</CODE>, and
250     * its value is changed to be the <CODE>value</CODE> parameter. This value is
251     * a simple string, it is not parsed as it is being set. So any markup (such
252     * as syntax to be recognized as an entity reference) is treated as literal
253     * text, and needs to be appropriately escaped by the implementation when it
254     * is written out. In order to assign an attribute value that contains entity
255     * references, the user must create an <CODE>DOMAttr</CODE>
256     * node plus any <CODE>DOMText</CODE> and <CODE>DOMEntityReference</CODE>
257     * nodes, build the appropriate subtree, and use
258     * <CODE>setAttributeNodeNS</CODE> or <CODE>setAttributeNode</CODE> to assign
259     * it as the value of an attribute.
260     *
261     * @param namespaceURI The <em>namespace URI</em> of
262     *    the attribute to create or alter.
263     * @param qualifiedName The <em>qualified name</em> of the
264     *    attribute to create or alter.
265     * @param value The value to set in string form.
266     * @exception DOMException
267     *   INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an
268     *   illegal character.
269     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
270     * <br>
271     *   NAMESPACE_ERR: Raised if the <CODE>qualifiedName</CODE> is
272     *        malformed, if the <CODE>qualifiedName</CODE> has a prefix and the
273     *        <CODE>namespaceURI</CODE> is <CODE>null</CODE> or an empty string,
274     *        if the <CODE>qualifiedName</CODE> has a prefix that is "xml" and the
275     *        <CODE>namespaceURI</CODE> is different from
276     *        "http://www.w3.org/XML/1998/namespace", if the
277     *        <CODE>qualifiedName</CODE> has a prefix that is "xmlns" and the
278     *        <CODE>namespaceURI</CODE> is different from
279     *        "http://www.w3.org/2000/xmlns/", or if the
280     *        <CODE>qualifiedName</CODE> is "xmlns" and the
281     *        <CODE>namespaceURI</CODE> is different from
282     *        "http://www.w3.org/2000/xmlns/".
283     * @since DOM Level 2
284     */
285    virtual void             setAttributeNS(const XMLCh *namespaceURI,
286                                            const XMLCh *qualifiedName, const XMLCh *value) = 0;
287
288    /**
289     * Removes an attribute by local name and namespace URI. If the
290     * removed attribute has a default value it is immediately replaced.
291     * The replacing attribute has the same namespace URI and local name, as well as
292     * the original prefix.
293     *
294     * @param namespaceURI The <em>namespace URI</em> of
295     *    the attribute to remove.
296     * @param localName The <em>local name</em> of the
297     *    attribute to remove.
298     * @exception DOMException
299     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
300     * @since DOM Level 2
301     */
302    virtual void              removeAttributeNS(const XMLCh *namespaceURI,
303                                                const XMLCh *localName) = 0;
304
305    /**
306     * Retrieves an <code>DOMAttr</code> node by local name and namespace URI.
307     *
308     * @param namespaceURI The <em>namespace URI</em> of
309     *    the attribute to retrieve.
310     * @param localName The <em>local name</em> of the
311     *    attribute to retrieve.
312     * @return The <code>DOMAttr</code> node with the specified attribute local
313     *    name and namespace URI or <code>null</code> if there is no such attribute.
314     * @since DOM Level 2
315     */
316    virtual DOMAttr      *  getAttributeNodeNS(const XMLCh *namespaceURI,
317                                               const XMLCh *localName) const = 0;
318
319    /**
320     * Adds a new attribute.
321     *
322     * If an attribute with that local name and namespace URI is already present
323     * in the element, it is replaced by the new one.
324     *
325     * @param newAttr The <code>DOMAttr</code> node to add to the attribute list.
326     * @return If the <code>newAttr</code> attribute replaces an existing
327     *    attribute with the same <em>local name</em> and <em>namespace URI</em>,
328     *    the replaced <code>DOMAttr</code> node is
329     *    returned, otherwise <code>null</code> is returned.
330     * @exception DOMException
331     *   WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
332     *   different document than the one that created the element.
333     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
334     *   <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
335     *   attribute of another <code>DOMElement</code> object. The DOM user must
336     *   explicitly clone <code>DOMAttr</code> nodes to re-use them in other
337     *   elements.
338     * @since DOM Level 2
339     */
340    virtual DOMAttr      *  setAttributeNodeNS(DOMAttr *newAttr) = 0;
341
342    /**
343     * Returns a <code>DOMNodeList</code> of all the <code>DOMElement</code>s
344     * with a given local name and namespace URI in the order in which they
345     * would be encountered in a preorder traversal of the
346     * <code>DOMDocument</code> tree, starting from this node.
347     *
348     * @param namespaceURI The <em>namespace URI</em> of
349     *    the elements to match on. The special value "*" matches all
350     *    namespaces.
351     * @param localName The <em>local name</em> of the
352     *    elements to match on. The special value "*" matches all local names.
353     * @return A new <code>DOMNodeList</code> object containing all the matched
354     *    <code>DOMElement</code>s.
355     * @since DOM Level 2
356     */
357    virtual DOMNodeList   * getElementsByTagNameNS(const XMLCh *namespaceURI,
358                                                   const XMLCh *localName) const = 0;
359
360    /**
361     * Returns <code>true</code> when an attribute with a given name is
362     * specified on this element or has a default value, <code>false</code>
363     * otherwise.
364     * @param name The name of the attribute to look for.
365     * @return <code>true</code> if an attribute with the given name is
366     *   specified on this element or has a default value, <code>false</code>
367     *    otherwise.
368     * @since DOM Level 2
369     */
370    virtual bool         hasAttribute(const XMLCh *name) const = 0;
371
372    /**
373     * Returns <code>true</code> when an attribute with a given local name and
374     * namespace URI is specified on this element or has a default value,
375     * <code>false</code> otherwise. HTML-only DOM implementations do not
376     * need to implement this method.
377     * @param namespaceURI The namespace URI of the attribute to look for.
378     * @param localName The local name of the attribute to look for.
379     * @return <code>true</code> if an attribute with the given local name
380     *   and namespace URI is specified or has a default value on this
381     *   element, <code>false</code> otherwise.
382     * @since DOM Level 2
383     */
384    virtual bool         hasAttributeNS(const XMLCh *namespaceURI,
385                                        const XMLCh *localName) const = 0;
386    //@}
387
388    /** @name Functions introduced in DOM Level 3 */
389    //@{
390
391    /**
392     * Declares the <code>DOMAttr</code> specified by name to be of type ID. If the
393     * value of the specified <code>DOMAttr</code> is unique then this element node
394     * can later be retrieved using getElementById on Document. Note, however,
395     * that this simply affects this node and does not change any grammar that
396     * may be in use.
397     * To specify an <code>DOMAttr</code> by local name and namespace URI, use the
398     * setIdAttributeNS method.
399     * @param name The name of the <code>DOMAttr</code>.
400     * @exception DOMException
401     *    NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
402     *    <br />NOT_FOUND_ERR: Raised if the specified node is not an <code>DOMAttr</code>
403     * of this element.
404     *
405     * <p><b>"Experimental - subject to change"</b></p>
406     *
407     * @since DOM Level 3
408     */
409    virtual void setIdAttribute(const XMLCh* name) = 0;
410
411
412    /**
413     * Declares the <code>DOMAttr</code> specified by local name and namespace
414     * URI to be of type ID. If the value of the specified <code>DOMAttr</code>
415     * is unique then this <code>DOMElement</code> node can later be retrieved
416     * using getElementById on <code>DOMDocument</code>. Note, however, that
417     * this simply affects this node and does not change any grammar that may
418     * be in use.
419     * @param namespaceURI The namespace URI of the <code>DOMAttr</code>.
420     * @param localName The local name of the <code>DOMAttr</code>.
421     * @exception  DOMException
422     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
423     *   <br />NOT_FOUND_ERR: Raised if the specified node is not an <code>DOMAttr</code> of this element.
424     *
425     * <p><b>"Experimental - subject to change"</b></p>
426     *
427     * @since DOM Level 3
428     */
429    virtual void setIdAttributeNS(const XMLCh* namespaceURI, const XMLCh* localName) = 0;
430
431
432
433    /**
434     * Declares the <code>DOMAttr</code> specified by node to be of type ID.
435     * If the value of the specified <code>DOMAttr</code> is unique then this
436     * <code>DOMElement</code> node can later be retrieved using getElementById
437     * on <code>DOMDocument</code>. Note, however, that this simply affects this
438     * node and does not change any grammar that may be in use.
439     * @param idAttr The <code>DOMAttr</code> node.
440     * @exception  DOMException
441     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
442     *   <br />NOT_FOUND_ERR: Raised if the specified node is not an <code>DOMAttr</code> of this element.
443     *
444     * <p><b>"Experimental - subject to change"</b></p>
445     *
446     * @since DOM Level 3
447     */
448    virtual void setIdAttributeNode(const DOMAttr *idAttr) = 0;
449
450
451
452    /**
453     * Returns the type information associated with this element.
454     *
455     * <p><b>"Experimental - subject to change"</b></p>
456     *
457     * @return the <code>DOMTypeInfo</code> associated with this element
458     * @since DOM level 3
459     */
460    virtual const DOMTypeInfo* getTypeInfo() const = 0;
461
462    //@}
463
464};
465
466XERCES_CPP_NAMESPACE_END
467
468#endif
469
470
471
Note: See TracBrowser for help on using the repository browser.