source: icXML/icXML-devel/src/xercesc/dom/DOMElement.hpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 23.0 KB
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: DOMElement.hpp 792236 2009-07-08 17:22:35Z amassari $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_DOMELEMENT_HPP)
23#define XERCESC_INCLUDE_GUARD_DOMELEMENT_HPP
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 * It also defines the ElementTraversal helper interface defined by http://www.w3.org/TR/2008/REC-ElementTraversal-20081222/
63 *
64 */
65
66class CDOM_EXPORT DOMElement: public DOMNode {
67protected:
68    // -----------------------------------------------------------------------
69    //  Hidden constructors
70    // -----------------------------------------------------------------------
71    /** @name Hidden constructors */
72    //@{   
73    DOMElement() {}
74    DOMElement(const DOMElement &other) : DOMNode(other) {}
75    //@}
76   
77private:
78    // -----------------------------------------------------------------------
79    // Unimplemented constructors and operators
80    // -----------------------------------------------------------------------
81    /** @name Unimplemented operators */
82    //@{
83    DOMElement & operator = (const DOMElement &);
84    //@}
85
86public:
87    // -----------------------------------------------------------------------
88    //  All constructors are hidden, just the destructor is available
89    // -----------------------------------------------------------------------
90    /** @name Destructor */
91    //@{
92    /**
93     * Destructor
94     *
95     */
96    virtual ~DOMElement() {};
97    //@}
98
99    // -----------------------------------------------------------------------
100    //  Virtual DOMElement interface
101    // -----------------------------------------------------------------------
102    /** @name Functions introduced in DOM Level 1 */
103    //@{
104    // -----------------------------------------------------------------------
105    //  Getter methods
106    // -----------------------------------------------------------------------
107    /**
108     * The name of the element.
109     *
110     * For example, in: &lt;elementExample
111     * id="demo"&gt;  ... &lt;/elementExample&gt; , <code>tagName</code> has
112     * the value <code>"elementExample"</code>. Note that this is
113     * case-preserving in XML, as are all of the operations of the DOM.
114     * @since DOM Level 1
115     */
116    virtual const XMLCh *         getTagName() const = 0;
117
118    /**
119     * Retrieves an attribute value by name.
120     *
121     * @param name The name of the attribute to retrieve.
122     * @return The <code>DOMAttr</code> value as a string, or the empty  string if
123     *   that attribute does not have a specified or default value.
124     * @since DOM Level 1
125     */
126    virtual const XMLCh *         getAttribute(const XMLCh *name) const = 0;
127
128    /**
129     * Retrieves an <code>DOMAttr</code> node by name.
130     *
131     * @param name The name (<CODE>nodeName</CODE>) of the attribute to retrieve.
132     * @return The <code>DOMAttr</code> node with the specified name (<CODE>nodeName</CODE>) or
133     *   <code>null</code> if there is no such attribute.
134     * @since DOM Level 1
135     */
136    virtual DOMAttr       * getAttributeNode(const XMLCh *name) const = 0;
137
138    /**
139     * Returns a <code>DOMNodeList</code> of all descendant elements with a given
140     * tag name, in the order in which they would be encountered in a preorder
141     * traversal of the <code>DOMElement</code> tree.
142     *
143     * @param name The name of the tag to match on. The special value "*"
144     *   matches all tags.
145     * @return A list of matching <code>DOMElement</code> nodes.
146     * @since DOM Level 1
147     */
148    virtual DOMNodeList   * getElementsByTagName(const XMLCh *name) const = 0;
149
150    // -----------------------------------------------------------------------
151    //  Setter methods
152    // -----------------------------------------------------------------------
153    /**
154     * Adds a new attribute.
155     *
156     * If an attribute with that name is already present
157     * in the element, its value is changed to be that of the value parameter.
158     * This value is a simple string, it is not parsed as it is being set. So
159     * any markup (such as syntax to be recognized as an entity reference) is
160     * treated as literal text, and needs to be appropriately escaped by the
161     * implementation when it is written out. In order to assign an attribute
162     * value that contains entity references, the user must create an
163     * <code>DOMAttr</code> node plus any <code>DOMText</code> and
164     * <code>DOMEntityReference</code> nodes, build the appropriate subtree, and
165     * use <code>setAttributeNode</code> to assign it as the value of an
166     * attribute.
167     * @param name The name of the attribute to create or alter.
168     * @param value Value to set in string form.
169     * @exception DOMException
170     *   INVALID_CHARACTER_ERR: Raised if the specified name contains an
171     *   illegal character.
172     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
173     * @since DOM Level 1
174     */
175    virtual void             setAttribute(const XMLCh *name,
176                                  const XMLCh *value) = 0;
177    /**
178     * Adds a new attribute.
179     *
180     * If an attribute with that name (<CODE>nodeName</CODE>) is already present
181     * in the element, it is replaced by the new one.
182     * @param newAttr The <code>DOMAttr</code> node to add to the attribute list.
183     * @return If the <code>newAttr</code> attribute replaces an existing
184     *   attribute, the replaced
185     *   <code>DOMAttr</code> node is returned, otherwise <code>null</code> is
186     *   returned.
187     * @exception DOMException
188     *   WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
189     *   different document than the one that created the element.
190     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
191     *   <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
192     *   attribute of another <code>DOMElement</code> object. The DOM user must
193     *   explicitly clone <code>DOMAttr</code> nodes to re-use them in other
194     *   elements.
195     * @since DOM Level 1
196     */
197    virtual DOMAttr       * setAttributeNode(DOMAttr *newAttr) = 0;
198
199    /**
200     * Removes the specified attribute node.
201     * If the removed <CODE>DOMAttr</CODE>
202     *   has a default value it is immediately replaced. The replacing attribute
203     *   has the same namespace URI and local name, as well as the original prefix,
204     *   when applicable.
205     *
206     * @param oldAttr The <code>DOMAttr</code> node to remove from the attribute
207     *   list.
208     * @return The <code>DOMAttr</code> node that was removed.
209     * @exception DOMException
210     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
211     *   <br>NOT_FOUND_ERR: Raised if <code>oldAttr</code> is not an attribute
212     *   of the element.
213     * @since DOM Level 1
214     */
215    virtual DOMAttr       * removeAttributeNode(DOMAttr *oldAttr) = 0;
216
217    /**
218     * Removes an attribute by name.
219     *
220     * If the removed attribute
221     *   is known to have a default value, an attribute immediately appears
222     *   containing the default value as well as the corresponding namespace URI,
223     *   local name, and prefix when applicable.<BR>To remove an attribute by local
224     *   name and namespace URI, use the <CODE>removeAttributeNS</CODE> method.
225     * @param name The name of the attribute to remove.
226     * @exception DOMException
227     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
228     * @since DOM Level 1
229     */
230    virtual void              removeAttribute(const XMLCh *name) = 0;
231    //@}
232
233    /** @name Functions introduced in DOM Level 2. */
234    //@{
235    /**
236     * Retrieves an attribute value by local name and namespace URI.
237     *
238     * @param namespaceURI The <em>namespace URI</em> of
239     *    the attribute to retrieve.
240     * @param localName The <em>local name</em> of the
241     *    attribute to retrieve.
242     * @return The <code>DOMAttr</code> value as a string, or an <CODE>null</CODE> if
243     *    that attribute does not have a specified or default value.
244     * @since DOM Level 2
245     */
246    virtual const XMLCh *         getAttributeNS(const XMLCh *namespaceURI,
247                                                 const XMLCh *localName) const = 0;
248
249    /**
250     * Adds a new attribute. If an attribute with the same
251     * local name and namespace URI is already present on the element, its prefix
252     * is changed to be the prefix part of the <CODE>qualifiedName</CODE>, and
253     * its value is changed to be the <CODE>value</CODE> parameter. This value is
254     * a simple string, it is not parsed as it is being set. So any markup (such
255     * as syntax to be recognized as an entity reference) is treated as literal
256     * text, and needs to be appropriately escaped by the implementation when it
257     * is written out. In order to assign an attribute value that contains entity
258     * references, the user must create an <CODE>DOMAttr</CODE>
259     * node plus any <CODE>DOMText</CODE> and <CODE>DOMEntityReference</CODE>
260     * nodes, build the appropriate subtree, and use
261     * <CODE>setAttributeNodeNS</CODE> or <CODE>setAttributeNode</CODE> to assign
262     * it as the value of an attribute.
263     *
264     * @param namespaceURI The <em>namespace URI</em> of
265     *    the attribute to create or alter.
266     * @param qualifiedName The <em>qualified name</em> of the
267     *    attribute to create or alter.
268     * @param value The value to set in string form.
269     * @exception DOMException
270     *   INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an
271     *   illegal character.
272     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
273     * <br>
274     *   NAMESPACE_ERR: Raised if the <CODE>qualifiedName</CODE> is
275     *        malformed, if the <CODE>qualifiedName</CODE> has a prefix and the
276     *        <CODE>namespaceURI</CODE> is <CODE>null</CODE> or an empty string,
277     *        if the <CODE>qualifiedName</CODE> has a prefix that is "xml" and the
278     *        <CODE>namespaceURI</CODE> is different from
279     *        "http://www.w3.org/XML/1998/namespace", if the
280     *        <CODE>qualifiedName</CODE> has a prefix that is "xmlns" and the
281     *        <CODE>namespaceURI</CODE> is different from
282     *        "http://www.w3.org/2000/xmlns/", or if the
283     *        <CODE>qualifiedName</CODE> is "xmlns" and the
284     *        <CODE>namespaceURI</CODE> is different from
285     *        "http://www.w3.org/2000/xmlns/".
286     * @since DOM Level 2
287     */
288    virtual void             setAttributeNS(const XMLCh *namespaceURI,
289                                            const XMLCh *qualifiedName, const XMLCh *value) = 0;
290
291    /**
292     * Removes an attribute by local name and namespace URI. If the
293     * removed attribute has a default value it is immediately replaced.
294     * The replacing attribute has the same namespace URI and local name, as well as
295     * the original prefix.
296     *
297     * @param namespaceURI The <em>namespace URI</em> of
298     *    the attribute to remove.
299     * @param localName The <em>local name</em> of the
300     *    attribute to remove.
301     * @exception DOMException
302     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
303     * @since DOM Level 2
304     */
305    virtual void              removeAttributeNS(const XMLCh *namespaceURI,
306                                                const XMLCh *localName) = 0;
307
308    /**
309     * Retrieves an <code>DOMAttr</code> node by local name and namespace URI.
310     *
311     * @param namespaceURI The <em>namespace URI</em> of
312     *    the attribute to retrieve.
313     * @param localName The <em>local name</em> of the
314     *    attribute to retrieve.
315     * @return The <code>DOMAttr</code> node with the specified attribute local
316     *    name and namespace URI or <code>null</code> if there is no such attribute.
317     * @since DOM Level 2
318     */
319    virtual DOMAttr      *  getAttributeNodeNS(const XMLCh *namespaceURI,
320                                               const XMLCh *localName) const = 0;
321
322    /**
323     * Adds a new attribute.
324     *
325     * If an attribute with that local name and namespace URI is already present
326     * in the element, it is replaced by the new one.
327     *
328     * @param newAttr The <code>DOMAttr</code> node to add to the attribute list.
329     * @return If the <code>newAttr</code> attribute replaces an existing
330     *    attribute with the same <em>local name</em> and <em>namespace URI</em>,
331     *    the replaced <code>DOMAttr</code> node is
332     *    returned, otherwise <code>null</code> is returned.
333     * @exception DOMException
334     *   WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
335     *   different document than the one that created the element.
336     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
337     *   <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
338     *   attribute of another <code>DOMElement</code> object. The DOM user must
339     *   explicitly clone <code>DOMAttr</code> nodes to re-use them in other
340     *   elements.
341     * @since DOM Level 2
342     */
343    virtual DOMAttr      *  setAttributeNodeNS(DOMAttr *newAttr) = 0;
344
345    /**
346     * Returns a <code>DOMNodeList</code> of all the <code>DOMElement</code>s
347     * with a given local name and namespace URI in the order in which they
348     * would be encountered in a preorder traversal of the
349     * <code>DOMDocument</code> tree, starting from this node.
350     *
351     * @param namespaceURI The <em>namespace URI</em> of
352     *    the elements to match on. The special value "*" matches all
353     *    namespaces.
354     * @param localName The <em>local name</em> of the
355     *    elements to match on. The special value "*" matches all local names.
356     * @return A new <code>DOMNodeList</code> object containing all the matched
357     *    <code>DOMElement</code>s.
358     * @since DOM Level 2
359     */
360    virtual DOMNodeList   * getElementsByTagNameNS(const XMLCh *namespaceURI,
361                                                   const XMLCh *localName) const = 0;
362
363    /**
364     * Returns <code>true</code> when an attribute with a given name is
365     * specified on this element or has a default value, <code>false</code>
366     * otherwise.
367     * @param name The name of the attribute to look for.
368     * @return <code>true</code> if an attribute with the given name is
369     *   specified on this element or has a default value, <code>false</code>
370     *    otherwise.
371     * @since DOM Level 2
372     */
373    virtual bool         hasAttribute(const XMLCh *name) const = 0;
374
375    /**
376     * Returns <code>true</code> when an attribute with a given local name and
377     * namespace URI is specified on this element or has a default value,
378     * <code>false</code> otherwise. HTML-only DOM implementations do not
379     * need to implement this method.
380     * @param namespaceURI The namespace URI of the attribute to look for.
381     * @param localName The local name of the attribute to look for.
382     * @return <code>true</code> if an attribute with the given local name
383     *   and namespace URI is specified or has a default value on this
384     *   element, <code>false</code> otherwise.
385     * @since DOM Level 2
386     */
387    virtual bool         hasAttributeNS(const XMLCh *namespaceURI,
388                                        const XMLCh *localName) const = 0;
389    //@}
390
391    /** @name Functions introduced in DOM Level 3 */
392    //@{
393
394    /**
395     * If the parameter isId is <code>true</code>, this method declares the specified
396     * attribute to be a user-determined ID attribute.
397     * This affects the value of <code>DOMAttr::isId</code> and the behavior of
398     * <code>DOMDocument::getElementById</code>, but does not change any schema that
399     * may be in use, in particular this does not affect the <code>DOMAttr::getSchemaTypeInfo</code>
400     * of the specified DOMAttr node. Use the value <code>false</code> for the parameter isId
401     * to undeclare an attribute for being a user-determined ID attribute.
402     * To specify an <code>DOMAttr</code> by local name and namespace URI, use the
403     * setIdAttributeNS method.
404     *
405     * @param name The name of the <code>DOMAttr</code>.
406     * @param isId Whether the attribute is of type ID.
407     * @exception DOMException
408     *    NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.<br>
409     *    NOT_FOUND_ERR: Raised if the specified node is not an <code>DOMAttr</code>
410     * of this element.
411     *
412     * @since DOM Level 3
413     */
414    virtual void setIdAttribute(const XMLCh* name, bool isId) = 0;
415
416
417    /**
418     * If the parameter isId is <code>true</code>, this method declares the specified
419     * attribute to be a user-determined ID attribute.
420     * This affects the value of <code>DOMAttr::isId</code> and the behavior of
421     * <code>DOMDocument::getElementById</code>, but does not change any schema that
422     * may be in use, in particular this does not affect the <code>DOMAttr::getSchemaTypeInfo</code>
423     * of the specified DOMAttr node. Use the value <code>false</code> for the parameter isId
424     * to undeclare an attribute for being a user-determined ID attribute.
425     *
426     * @param namespaceURI The namespace URI of the <code>DOMAttr</code>.
427     * @param localName The local name of the <code>DOMAttr</code>.
428     * @param isId Whether the attribute is of type ID.
429     * @exception  DOMException
430     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.<br>
431     *   NOT_FOUND_ERR: Raised if the specified node is not an <code>DOMAttr</code> of this element.
432     *
433     * @since DOM Level 3
434     */
435    virtual void setIdAttributeNS(const XMLCh* namespaceURI, const XMLCh* localName, bool isId) = 0;
436
437
438
439    /**
440     * If the parameter isId is <code>true</code>, this method declares the specified
441     * attribute to be a user-determined ID attribute.
442     * This affects the value of <code>DOMAttr::isId</code> and the behavior of
443     * <code>DOMDocument::getElementById</code>, but does not change any schema that
444     * may be in use, in particular this does not affect the <code>DOMAttr::getSchemaTypeInfo</code>
445     * of the specified DOMAttr node. Use the value <code>false</code> for the parameter isId
446     * to undeclare an attribute for being a user-determined ID attribute.
447     *
448     * @param idAttr The <code>DOMAttr</code> node.
449     * @param isId Whether the attribute is of type ID.
450     * @exception  DOMException
451     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.<br>
452     *   NOT_FOUND_ERR: Raised if the specified node is not an <code>DOMAttr</code> of this element.
453     *
454     * @since DOM Level 3
455     */
456    virtual void setIdAttributeNode(const DOMAttr *idAttr, bool isId) = 0;
457
458
459
460    /**
461     * Returns the type information associated with this element.
462     *
463     * @return the <code>DOMTypeInfo</code> associated with this element
464     * @since DOM level 3
465     */
466    virtual const DOMTypeInfo* getSchemaTypeInfo() const = 0;
467
468    //@}
469
470    // -----------------------------------------------------------------------
471    //  DOMElementTraversal interface
472    // -----------------------------------------------------------------------
473    /** @name Functions introduced in the ElementTraversal specification (http://www.w3.org/TR/2008/REC-ElementTraversal-20081222/)*/
474    //@{
475    // -----------------------------------------------------------------------
476    //  Getter methods
477    // -----------------------------------------------------------------------
478    /**
479     * The first child of type DOMElement.
480     *
481     * @return The <code>DOMElement</code> object that is the first element node
482     *   among the child nodes of this node, or <code>null</code> if there is none.
483     */
484    virtual DOMElement *         getFirstElementChild() const = 0;
485
486    /**
487     * The last child of type DOMElement.
488     *
489     * @return The <code>DOMElement</code> object that is the last element node
490     *   among the child nodes of this node, or <code>null</code> if there is none.
491     */
492    virtual DOMElement *         getLastElementChild() const = 0;
493
494    /**
495     * The previous sibling node of type DOMElement.
496     *
497     * @return The <code>DOMElement</code> object that is the previous sibling element node
498     *   in document order, or <code>null</code> if there is none.
499     */
500    virtual DOMElement *         getPreviousElementSibling() const = 0;
501
502    /**
503     * The next sibling node of type DOMElement.
504     *
505     * @return The <code>DOMElement</code> object that is the next sibling element node
506     *   in document order, or <code>null</code> if there is none.
507     */
508    virtual DOMElement *         getNextElementSibling() const = 0;
509
510    /**
511     * The number of child nodes that are of type DOMElement.
512     *
513     * Note: the count is computed every time this function is invoked
514     *
515     * @return The number of <code>DOMElement</code> objects that are direct children
516     *   of this object (nested elements are not counted), or <code>0</code> if there is none.
517     *
518     */
519    virtual XMLSize_t            getChildElementCount() const = 0;
520    //@}
521};
522
523XERCES_CPP_NAMESPACE_END
524
525#endif
526
527
528
Note: See TracBrowser for help on using the repository browser.