IDOM_Element.hpp
上传用户:huihehuasu
上传日期:2007-01-10
资源大小:6948k
文件大小:16k
源码类别:

xml/soap/webservice

开发平台:

C/C++

  1. /*
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2001 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Xerces" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation, and was
  51.  * originally based on software copyright (c) 2001, International
  52.  * Business Machines, Inc., http://www.ibm.com .  For more information
  53.  * on the Apache Software Foundation, please see
  54.  * <http://www.apache.org/>.
  55.  */
  56. /*
  57.  * $Log: IDOM_Element.hpp,v $
  58.  * Revision 1.2  2001/05/11 13:25:52  tng
  59.  * Copyright update.
  60.  *
  61.  * Revision 1.1.1.1  2001/04/03 00:14:29  andyh
  62.  * IDOM
  63.  *
  64.  */
  65. #ifndef IDOM_Element_HEADER_GUARD_
  66. #define IDOM_Element_HEADER_GUARD_
  67. #include <util/XercesDefs.hpp>
  68. #include "IDOM_Node.hpp"
  69. class IDOM_Attr;
  70. class IDOM_NodeList;
  71. /**
  72.  * By far the vast majority of objects (apart from text) that authors
  73.  * encounter when traversing a document are <code>IDOM_Element</code> nodes.
  74.  *
  75.  * Assume the following XML document:&lt;elementExample id="demo"&gt;
  76.  * &lt;subelement1/&gt;
  77.  * &lt;subelement2&gt;&lt;subsubelement/&gt;&lt;/subelement2&gt;
  78.  * &lt;/elementExample&gt;
  79.  * <p>When represented using DOM, the top node is an <code>IDOM_Element</code> node
  80.  * for "elementExample", which contains two child <code>IDOM_Element</code> nodes,
  81.  * one for "subelement1" and one for "subelement2". "subelement1" contains no
  82.  * child nodes.
  83.  * <p>Elements may have attributes associated with them; since the
  84.  * <code>IDOM_Element</code> interface inherits from <code>IDOM_Node</code>, the generic
  85.  *  <code>IDOM_Node</code> interface method <code>getAttributes</code> may be used
  86.  * to retrieve the set of all attributes for an element.  There are methods on
  87.  *  the <code>IDOM_Element</code> interface to retrieve either an <code>IDOM_Attr</code>
  88.  *  object by name or an attribute value by name. In XML, where an attribute
  89.  * value may contain entity references, an <code>IDOM_Attr</code> object should be
  90.  * retrieved to examine the possibly fairly complex sub-tree representing the
  91.  * attribute value. On the other hand, in HTML, where all attributes have
  92.  * simple string values, methods to directly access an attribute value can
  93.  * safely be used as a convenience.
  94.  */
  95. class CDOM_EXPORT IDOM_Element: public IDOM_Node {
  96. protected:
  97.     IDOM_Element() {};
  98.     IDOM_Element(const IDOM_Element &other) {};
  99.     IDOM_Element & operator = (const IDOM_Element &other) {return *this;};
  100. public:
  101.     /** @name Constructors and assignment operator */
  102.     //@{
  103.     //@}
  104.     /** @name Destructor. */
  105.     //@{
  106.  /**
  107.       * Destructor.  The object being destroyed is the reference
  108.       * object, not the underlying Element itself.
  109.   *
  110.   */
  111.     virtual ~IDOM_Element() {};
  112.     //@}
  113.     /** @name Getter functions. */
  114.     //@{
  115.   /**
  116.    * The name of the element.
  117.    *
  118.    * For example, in: &lt;elementExample
  119.    * id="demo"&gt;  ... &lt;/elementExample&gt; , <code>tagName</code> has
  120.    * the value <code>"elementExample"</code>. Note that this is
  121.    * case-preserving in XML, as are all of the operations of the DOM.
  122.    */
  123.   virtual const XMLCh *         getTagName() const = 0;
  124.   /**
  125.    * Retrieves an attribute value by name.
  126.    *
  127.    * @param name The name of the attribute to retrieve.
  128.    * @return The <code>IDOM_Attr</code> value as a string, or the empty  string if
  129.    *   that attribute does not have a specified or default value.
  130.    */
  131.   virtual const XMLCh *         getAttribute(const XMLCh *name) const = 0;
  132.   /**
  133.    * Retrieves an <code>IDOM_Attr</code> node by name.
  134.    *
  135.    * @param name The name (<CODE>nodeName</CODE>) of the attribute to retrieve.
  136.    * @return The <code>IDOM_Attr</code> node with the specified name (<CODE>nodeName</CODE>) or
  137.    *   <code>null</code> if there is no such attribute.
  138.    */
  139.   virtual IDOM_Attr       * getAttributeNode(const XMLCh *name) const = 0;
  140.   /**
  141.    * Returns a <code>NodeList</code> of all descendant elements with a given
  142.    * tag name, in the order in which they would be encountered in a preorder
  143.    * traversal of the <code>IDOM_Element</code> tree.
  144.    *
  145.    * @param name The name of the tag to match on. The special value "*"
  146.    *   matches all tags.
  147.    * @return A list of matching <code>IDOM_Element</code> nodes.
  148.    */
  149.   virtual IDOM_NodeList   * getElementsByTagName(const XMLCh *name) const = 0;
  150.   //@}
  151.   /** @name Set functions. */
  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>IDOM_Attr</code> node plus any <code>Text</code> and
  164.    * <code>EntityReference</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.    */
  174.    virtual void             setAttribute(const XMLCh *name,
  175.                                  const XMLCh *value) = 0;
  176.    /**
  177.     * Adds a new attribute.
  178.     *
  179.     * If an attribute with that name (<CODE>nodeName</CODE>) is already present
  180.     * in the element, it is replaced by the new one.
  181.     * @param newAttr The <code>IDOM_Attr</code> node to add to the attribute list.
  182.     * @return If the <code>newAttr</code> attribute replaces an existing
  183.     *   attribute, the replaced
  184.     *   <code>IDOM_Attr</code> node is returned, otherwise <code>null</code> is
  185.     *   returned.
  186.     * @exception DOMException
  187.     *   WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
  188.     *   different document than the one that created the element.
  189.     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  190.     *   <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
  191.     *   attribute of another <code>IDOM_Element</code> object. The DOM user must
  192.     *   explicitly clone <code>IDOM_Attr</code> nodes to re-use them in other
  193.     *   elements.
  194.     */
  195.    virtual IDOM_Attr       * setAttributeNode(IDOM_Attr *newAttr) = 0;
  196.    //@}
  197.    /** @name Functions which modify the Element. */
  198.    //@{
  199.   /**
  200.    * Removes the specified attribute node.
  201.    * If the removed <CODE>IDOM_Attr</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>IDOM_Attr</code> node to remove from the attribute
  207.    *   list.
  208.    * @return The <code>IDOM_Attr</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.    */
  214.   virtual IDOM_Attr       * removeAttributeNode(IDOM_Attr *oldAttr) = 0;
  215.   /**
  216.    * Removes an attribute by name.
  217.    *
  218.    * If the removed attribute
  219.    *   is known to have a default value, an attribute immediately appears
  220.    *   containing the default value as well as the corresponding namespace URI,
  221.    *   local name, and prefix when applicable.<BR>To remove an attribute by local
  222.    *   name and namespace URI, use the <CODE>removeAttributeNS</CODE> method.
  223.    * @param name The name of the attribute to remove.
  224.    * @exception DOMException
  225.    *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  226.    */
  227.   virtual void              removeAttribute(const XMLCh *name) = 0;
  228.   //@}
  229.   /** @name Functions introduced in DOM Level 2. */
  230.   //@{
  231.   /**
  232.    * Retrieves an attribute value by local name and namespace URI.
  233.    *
  234.    * <p><b>"Experimental - subject to change"</b></p>
  235.    *
  236.    * @param namespaceURI The <em>namespace URI</em> of
  237.    *    the attribute to retrieve.
  238.    * @param localName The <em>local name</em> of the
  239.    *    attribute to retrieve.
  240.    * @return The <code>IDOM_Attr</code> value as a string, or an <CODE>null</CODE> if
  241.    *    that attribute does not have a specified or default value.
  242.    */
  243.   virtual const XMLCh *         getAttributeNS(const XMLCh *namespaceURI,
  244. const XMLCh *localName) const = 0;
  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>IDOM_Attr</CODE>
  255.    * node plus any <CODE>IDOM_Text</CODE> and <CODE>IDOM_EntityReference</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.    * <p><b>"Experimental - subject to change"</b></p>
  261.    *
  262.    * @param namespaceURI The <em>namespace URI</em> of
  263.    *    the attribute to create or alter.
  264.    * @param qualifiedName The <em>qualified name</em> of the
  265.    *    attribute to create or alter.
  266.    * @param value The value to set in string form.
  267.    * @exception DOMException
  268.    *   INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an
  269.    *   illegal character.
  270.    *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  271.    * <br>
  272.    *   NAMESPACE_ERR: Raised if the <CODE>qualifiedName</CODE> is
  273.    *        malformed, if the <CODE>qualifiedName</CODE> has a prefix and the
  274.    *        <CODE>namespaceURI</CODE> is <CODE>null</CODE> or an empty string,
  275.    *        if the <CODE>qualifiedName</CODE> has a prefix that is "xml" and the
  276.    *        <CODE>namespaceURI</CODE> is different from
  277.    *        "http://www.w3.org/XML/1998/namespace", if the
  278.    *        <CODE>qualifiedName</CODE> has a prefix that is "xmlns" and the
  279.    *        <CODE>namespaceURI</CODE> is different from
  280.    *        "http://www.w3.org/2000/xmlns/", or if the
  281.    *        <CODE>qualifiedName</CODE> is "xmlns" and the
  282.    *        <CODE>namespaceURI</CODE> is different from
  283.    *        "http://www.w3.org/2000/xmlns/".
  284.    */
  285.    virtual void             setAttributeNS(const XMLCh *namespaceURI,
  286. const XMLCh *qualifiedName, const XMLCh *value) = 0;
  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.    * <p><b>"Experimental - subject to change"</b></p>
  294.    *
  295.    * @param namespaceURI The <em>namespace URI</em> of
  296.    *    the attribute to remove.
  297.    * @param localName The <em>local name</em> of the
  298.    *    attribute to remove.
  299.    * @exception DOMException
  300.    *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  301.    */
  302.   virtual void              removeAttributeNS(const XMLCh *namespaceURI,
  303. const XMLCh *localName) = 0;
  304.   /**
  305.    * Retrieves an <code>IDOM_Attr</code> node by local name and namespace URI.
  306.    *
  307.    * <p><b>"Experimental - subject to change"</b></p>
  308.    *
  309.    * @param namespaceURI The <em>namespace URI</em> of
  310.    *    the attribute to retrieve.
  311.    * @param localName The <em>local name</em> of the
  312.    *    attribute to retrieve.
  313.    * @return The <code>IDOM_Attr</code> node with the specified attribute local
  314.    *    name and namespace URI or <code>null</code> if there is no such attribute.
  315.    */
  316.   virtual IDOM_Attr      *  getAttributeNodeNS(const XMLCh *namespaceURI,
  317. const XMLCh *localName) const = 0;
  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.     * <p><b>"Experimental - subject to change"</b></p>
  325.     *
  326.     * @param newAttr The <code>IDOM_Attr</code> node to add to the attribute list.
  327.     * @return If the <code>newAttr</code> attribute replaces an existing
  328.     *    attribute with the same <em>local name</em> and <em>namespace URI</em>,
  329.     *    the replaced <code>IDOM_Attr</code> node is
  330.     *    returned, otherwise <code>null</code> is returned.
  331.     * @exception DOMException
  332.     *   WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
  333.     *   different document than the one that created the element.
  334.     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  335.     *   <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
  336.     *   attribute of another <code>IDOM_Element</code> object. The DOM user must
  337.     *   explicitly clone <code>IDOM_Attr</code> nodes to re-use them in other
  338.     *   elements.
  339.     */
  340.    virtual IDOM_Attr      *  setAttributeNodeNS(IDOM_Attr *newAttr) = 0;
  341.   /**
  342.    * Returns a <code>IDOM_NodeList</code> of all the <code>IDOM_Element</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>IDOM_Document</code> tree, starting from this node.
  346.    *
  347.    * <p><b>"Experimental - subject to change"</b></p>
  348.    *
  349.    * @param namespaceURI The <em>namespace URI</em> of
  350.    *    the elements to match on. The special value "*" matches all
  351.    *    namespaces.
  352.    * @param localName The <em>local name</em> of the
  353.    *    elements to match on. The special value "*" matches all local names.
  354.    * @return A new <code>IDOM_NodeList</code> object containing all the matched
  355.    *    <code>IDOM_Element</code>s.
  356.    */
  357.   virtual IDOM_NodeList   * getElementsByTagNameNS(const XMLCh *namespaceURI,
  358. const XMLCh *localName) const = 0;
  359.   //@}
  360. };
  361. #endif