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

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

xerces added

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