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

xml/soap/webservice

开发平台:

C/C++

  1. #ifndef IDOM_Document_HEADER_GUARD_
  2. #define IDOM_Document_HEADER_GUARD_
  3. /*
  4.  * The Apache Software License, Version 1.1
  5.  *
  6.  * Copyright (c) 2001 The Apache Software Foundation.  All rights
  7.  * reserved.
  8.  *
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions
  11.  * are met:
  12.  *
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  *
  16.  * 2. Redistributions in binary form must reproduce the above copyright
  17.  *    notice, this list of conditions and the following disclaimer in
  18.  *    the documentation and/or other materials provided with the
  19.  *    distribution.
  20.  *
  21.  * 3. The end-user documentation included with the redistribution,
  22.  *    if any, must include the following acknowledgment:
  23.  *       "This product includes software developed by the
  24.  *        Apache Software Foundation (http://www.apache.org/)."
  25.  *    Alternately, this acknowledgment may appear in the software itself,
  26.  *    if and wherever such third-party acknowledgments normally appear.
  27.  *
  28.  * 4. The names "Xerces" and "Apache Software Foundation" must
  29.  *    not be used to endorse or promote products derived from this
  30.  *    software without prior written permission. For written
  31.  *    permission, please contact apache@apache.org.
  32.  *
  33.  * 5. Products derived from this software may not be called "Apache",
  34.  *    nor may "Apache" appear in their name, without prior written
  35.  *    permission of the Apache Software Foundation.
  36.  *
  37.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  38.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  39.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  40.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  41.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  42.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  43.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  44.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  45.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  46.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  47.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  48.  * SUCH DAMAGE.
  49.  * ====================================================================
  50.  *
  51.  * This software consists of voluntary contributions made by many
  52.  * individuals on behalf of the Apache Software Foundation, and was
  53.  * originally based on software copyright (c) 2001, International
  54.  * Business Machines, Inc., http://www.ibm.com .  For more information
  55.  * on the Apache Software Foundation, please see
  56.  * <http://www.apache.org/>.
  57.  */
  58. /*
  59.  * $Id: IDOM_Document.hpp,v 1.4 2001/06/08 21:23:03 tng Exp $
  60. */
  61. #include <util/XercesDefs.hpp>
  62. #include "IDOM_Node.hpp"
  63. class IDNodeIteratorImpl;
  64. class IDOM_DocumentType;
  65. class IDOM_Element;
  66. class IDOM_DocumentFragment;
  67. class IDOM_Comment;
  68. class IDOM_CDATASection;
  69. class IDOM_ProcessingInstruction;
  70. class IDOM_Attr;
  71. class IDOM_Entity;
  72. class IDOM_EntityReference;
  73. class IDOM_DOMImplementation;
  74. class IDOM_NodeFilter;
  75. class IDOM_NodeList;
  76. class IDOM_Notation;
  77. class IDOM_Text;
  78. class IDOM_Node;
  79. class IDOM_NodeIterator;
  80. class IDOM_TreeWalker;
  81. class IDOM_Range;
  82. /**
  83. * Class to refer to XML Document nodes in the IDOM.
  84. *
  85. * Conceptually, a IDOM document node is the root of the document tree, and provides
  86. * the  primary access to the document's data.
  87. * <p>Since elements, text nodes, comments, processing instructions, etc.
  88. * cannot exist outside the context of a <code>Document</code>, the
  89. * <code>Document</code> interface also contains the factory methods needed
  90. * to create these objects.  The <code>Node</code> objects created have a
  91. * <code>ownerDocument</code> attribute which associates them with the
  92. * <code>Document</code> within whose  context they were created.
  93. */
  94. class CDOM_EXPORT IDOM_Document: public IDOM_Node {
  95. protected:
  96.     /** @name Constructors and assignment operators */
  97.     //@{
  98.     /**
  99.      * The default constructor for IDOM_Document creates a null
  100.      * IDOM_Document object that refers to no document.  It may subsequently be
  101.      * assigned to refer to an actual Document node.
  102.      *
  103.      * To create a new document, use the DOMImplementation
  104.      *   <code> IDOM_DOMImplementation::createDocument(). </code>
  105.      *
  106.      */
  107.     IDOM_Document() {};
  108.     /**
  109.       * Copy constructor.  Creates a new <code>IDOM_Document</code> that refers to the
  110.       * same underlying actual document as the original.
  111.       *
  112.       * @param other The object to be copied
  113.       */
  114.     IDOM_Document(const IDOM_Document &other) {};
  115.     /**
  116.       * Assignment operator
  117.       *
  118.       * @param other The object to be copied
  119.       */
  120.     IDOM_Document & operator = (const IDOM_Document &other) {return *this;};
  121. //@}
  122. public:
  123.   /** @name Destructor */
  124.   //@{
  125.     virtual ~IDOM_Document() {};
  126.   //@}
  127.   /** @name Factory methods to create new nodes for the Document */
  128.   //@{
  129.     /**
  130.     *  Create a new entity.
  131.     *
  132.     *  Non-standard extension.
  133.     * @param name The name of the entity to instantiate
  134.     *
  135.     */
  136.     virtual IDOM_Entity     *createEntity(const XMLCh *name) = 0;
  137.     /**
  138.     * Creates an element of the type specified.
  139.     *
  140.     * Note that the instance returned
  141.     * implements the Element interface, so attributes can be specified
  142.     * directly  on the returned object.
  143.     * @param tagName The name of the element type to instantiate.
  144.     * @return A <code>IDOM_Element</code> that reference the new element.
  145.     * @exception IDOMException
  146.     *   INVALID_CHARACTER_ERR: Raised if the specified name contains an
  147.     *   illegal character.
  148.     */
  149.     virtual IDOM_Element     *createElement(const XMLCh *tagName) = 0;
  150.     /**
  151.     * Creates an empty DocumentFragment object.
  152.     *
  153.     * @return A <code>IDOM_DocumentFragment</code> that references the newly
  154.     * created document fragment.
  155.     */
  156.     virtual IDOM_DocumentFragment   *createDocumentFragment() = 0;
  157.     /**
  158.     * Creates a Text node given the specified string.
  159.     *
  160.     * @param data The data for the node.
  161.     * @return A <code>IDOM_Text</code> object that references the newly
  162.     *  created text node.
  163.     */
  164.     virtual IDOM_Text         *createTextNode(const XMLCh *data) = 0;
  165.     /**
  166.     * Creates a Comment node given the specified string.
  167.     *
  168.     * @param data The data for the comment.
  169.     * @return A <code>IDOM_Comment</code> that references the newly
  170.     *  created comment node.
  171.     */
  172.     virtual IDOM_Comment      *createComment(const XMLCh *data) = 0;
  173.     /**
  174.     * Creates a CDATASection node whose value  is the specified
  175.     * string.
  176.     *
  177.     * @param data The data for the <code>IDOM_CDATASection</code> contents.
  178.     * @return A <code>IDOM_CDATASection</code> object.
  179.     * @exception IDOMException
  180.     *   NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
  181.     */
  182.     virtual IDOM_CDATASection   *createCDATASection(const XMLCh *data) = 0;
  183.     /**
  184.     *  Create a DocumentType node.  Non-standard extension.
  185.     *
  186.     * @return A <code>IDOM_DocumentType</code> that references the newly
  187.     *  created DocumentType node.
  188.     *
  189.     */
  190.     virtual IDOM_DocumentType *createDocumentType(const XMLCh *name) = 0;
  191.     /**
  192.     *  Create a Notation.
  193.     *
  194.     *  Non-standard extension.
  195.     *
  196.     *  @param name The name of the notation to instantiate
  197.     * @return A <code>IDOM_Notation</code> that references the newly
  198.     *  created Notation node.
  199.     */
  200.     virtual IDOM_Notation *createNotation(const XMLCh *name) = 0;
  201.     /**
  202.     * Creates a ProcessingInstruction node given the specified
  203.     * name and data strings.
  204.     *
  205.     * @param target The target part of the processing instruction.
  206.     * @param data The data for the node.
  207.     * @return A <code>IDOM_ProcessingInstruction</code> that references the newly
  208.     *  created PI node.
  209.     * @exception IDOMException
  210.     *   INVALID_CHARACTER_ERR: Raised if an illegal character is specified.
  211.     */
  212.     virtual IDOM_ProcessingInstruction *createProcessingInstruction(const XMLCh *target,
  213.         const XMLCh *data) = 0;
  214.     /**
  215.      * Creates an Attr of the given name.
  216.      *
  217.      * Note that the
  218.      * <code>Attr</code> instance can then be attached to an Element
  219.      * using the <code>IDOMElement::setAttribute()</code> method.
  220.      * @param name The name of the attribute.
  221.      * @return A new <CODE>IDOM_Attr</CODE>
  222.      *       object with the <CODE>nodeName</CODE> attribute set to
  223.      *       <CODE>name</CODE>, and <CODE>localName</CODE>, <CODE>prefix</CODE>,
  224.      *       and <CODE>namespaceURI</CODE> set to
  225.      *       <CODE>null</CODE>.
  226.      * @exception IDOMException
  227.      *   INVALID_CHARACTER_ERR: Raised if the specified name contains an
  228.      *   illegal character.
  229.      */
  230.     virtual IDOM_Attr     *createAttribute(const XMLCh *name) = 0;
  231.     /**
  232.      * Creates an EntityReference object.
  233.      *
  234.      * @param name The name of the entity to reference.
  235.      * @return A <code>IDOM_EntityReference</code> that references the newly
  236.      *  created EntityReference node.
  237.      * @exception IDOMException
  238.      *   INVALID_CHARACTER_ERR: Raised if the specified name contains an
  239.      *   illegal character.
  240.      */
  241.     virtual IDOM_EntityReference    *createEntityReference(const XMLCh *name) = 0;
  242.     /**
  243.      * Creates a NodeIterator object.   (IDOM2)
  244.      *
  245.      * NodeIterators are used to step through a set of nodes, e.g. the set of nodes in a NodeList, the
  246.      * document subtree governed by a particular node, the results of a query, or any other set of nodes.
  247.      * The set of nodes to be iterated is determined by the implementation of the NodeIterator. IDOM Level 2
  248.      * specifies a single NodeIterator implementation for document-order traversal of a document subtree.
  249.      * Instances of these iterators are created by calling <code>DocumentTraversal.createNodeIterator()</code>.
  250.      *
  251.      * To produce a view of the document that has entity references expanded and does not
  252.      * expose the entity reference node itself, use the <code>whatToShow</code> flags to hide the entity
  253.      * reference node and set expandEntityReferences to true when creating the iterator. To
  254.      * produce a view of the document that has entity reference nodes but no entity expansion,
  255.      * use the <code>whatToShow</code> flags to show the entity reference node and set
  256.      * expandEntityReferences to false.
  257.      *
  258.      * <p><b>"Experimental - subject to change"</b></p>
  259.      *
  260.      * @param root The root node of the IDOM tree
  261.      * @param whatToShow This attribute determines which node types are presented via the iterator.
  262.      * @param filter The filter used to screen nodes
  263.      * @param entityReferenceExpansion The value of this flag determines whether the children of entity reference nodes are
  264.      *                   visible to the iterator. If false, they will be skipped over.
  265.      */
  266.     virtual IDOM_NodeIterator *createNodeIterator(IDOM_Node         *root,
  267.                                                    unsigned long    whatToShow,
  268.                                                    IDOM_NodeFilter* filter,
  269.                                                    bool             entityReferenceExpansion) = 0;
  270.      /**
  271.      * Creates a TreeWalker object.   (IDOM2)
  272.      *
  273.      * TreeWalker objects are used to navigate a document tree or subtree using the view of the document defined
  274.      * by its whatToShow flags and any filters that are defined for the TreeWalker. Any function which performs
  275.      * navigation using a TreeWalker will automatically support any view defined by a TreeWalker.
  276.      *
  277.      * Omitting nodes from the logical view of a subtree can result in a structure that is substantially different from
  278.      * the same subtree in the complete, unfiltered document. Nodes that are siblings in the TreeWalker view may
  279.      * be children of different, widely separated nodes in the original view. For instance, consider a Filter that skips
  280.      * all nodes except for Text nodes and the root node of a document. In the logical view that results, all text
  281.      * nodes will be siblings and appear as direct children of the root node, no matter how deeply nested the
  282.      * structure of the original document.
  283.      *
  284.      * To produce a view of the document that has entity references expanded
  285.      * and does not expose the entity reference node itself, use the whatToShow
  286.      * flags to hide the entity reference node and set <code>expandEntityReferences</code> to
  287.      * true when creating the TreeWalker. To produce a view of the document
  288.      * that has entity reference nodes but no entity expansion, use the
  289.      * <code>whatToShow</code> flags to show the entity reference node and set
  290.      * <code>expandEntityReferences</code> to false
  291.      *
  292.      * <p><b>"Experimental - subject to change"</b></p>
  293.      *
  294.      * @param root The root node of the IDOM tree
  295.      * @param whatToShow This attribute determines which node types are presented via the tree-walker.
  296.      * @param filter The filter used to screen nodes
  297.      * @param entityReferenceExpansion The value of this flag determines whether the children of entity reference nodes are
  298.      *                   visible to the tree-walker. If false, they will be skipped over.
  299.      */
  300.     virtual IDOM_TreeWalker  *createTreeWalker(IDOM_Node        *root,
  301.                                                unsigned long     whatToShow,
  302.                                                IDOM_NodeFilter  *filter,
  303.                                                bool              entityReferenceExpansion) = 0;
  304.     /**
  305.   * To create the range  consisting of boundary-points and offset of the
  306.       * selected contents
  307.       *
  308.       * @return The initial state of the Range such that both the boundary-points
  309.       * are positioned at the beginning of the corresponding IDOM_DOcument, before
  310.       * any content. The range returned can only be used to select content
  311.       * associated with this document, or with documentFragments and Attrs for
  312.       * which this document is the ownerdocument
  313.   */
  314.     virtual IDOM_Range    *createRange() = 0;
  315.     //@}
  316.     /** @name Getter functions */
  317.     //@{
  318.     /**
  319.      * Get Document Type Declaration (see <code>IDOM_DocumentType</code>) associated
  320.      * with  this document.
  321.      *
  322.      * For documents without
  323.      * a document type declaration this returns <code>null</code> reference object. The IDOM Level
  324.      *  1 does not support editing the Document Type Declaration, therefore
  325.      * <code>docType</code> cannot be altered in any way.
  326.      */
  327.     virtual IDOM_DocumentType       *getDoctype() const = 0;
  328.     /**
  329.      * Return the <code>IDOMImplementation</code> object that handles this document.
  330.      */
  331.     virtual IDOM_DOMImplementation  *getImplementation() const = 0;
  332.     /**
  333.      * Return a reference to the root element of the document.
  334.      */
  335.     virtual IDOM_Element     *getDocumentElement() const = 0;
  336.     /**
  337.      * Returns a <code>IDOM_NodeList</code> of all the elements with a
  338.      * given tag name.  The returned node list is "live", in that changes
  339.      * to the document tree made after a nodelist was initially
  340.      * returned will be immediately reflected in the node list.
  341.      *
  342.      * The elements in the node list are ordered in the same order in which they
  343.      * would be encountered in a
  344.      * preorder traversal of the <code>Document</code> tree.
  345.      * @param tagname The name of the tag to match on. The special value "*"
  346.      *   matches all tags.
  347.      * @return A reference to a NodeList containing all the matched
  348.      *   <code>Element</code>s.
  349.      */
  350.     virtual IDOM_NodeList      *getElementsByTagName(const XMLCh *tagname) const = 0;
  351.     //@}
  352.     /** @name Functions introduced in IDOM Level 2. */
  353.     //@{
  354.     /**
  355.      * Imports a node from another document to this document.
  356.      * The returned node has no parent (<CODE>parentNode</CODE> is
  357.      * <CODE>null</CODE>). The source node is not altered or removed from the
  358.      * original document; this method creates a new copy of the source
  359.      * node.<BR>For all nodes, importing a node creates a node object owned by
  360.      * the importing document, with attribute values identical to the source
  361.      * node's <CODE>nodeName</CODE> and <CODE>nodeType</CODE>, plus the
  362.      * attributes related to namespaces (prefix and namespaces URI).
  363.      *
  364.      * <p><b>"Experimental - subject to change"</b></p>
  365.      *
  366.      * @param importedNode The node to import.
  367.      * @param deep If <CODE>true</CODE>, recursively import the subtree under the
  368.      *      specified node; if <CODE>false</CODE>, import only the node itself,
  369.      *      as explained above. This does not apply to <CODE>IDOM_Attr</CODE>,
  370.      *      <CODE>IDOM_EntityReference</CODE>, and <CODE>IDOM_Notation</CODE> nodes.
  371.      * @return The imported node that belongs to this <CODE>IDOM_Document</CODE>.
  372.      * @exception IDOMException
  373.      *   NOT_SUPPORTED_ERR: Raised if the type of node being imported is
  374.      *                      not supported.
  375.      */
  376.     virtual IDOM_Node        *importNode(IDOM_Node *importedNode, bool deep) = 0;
  377.     /**
  378.      * Creates an element of the given qualified name and
  379.      * namespace URI.
  380.      *
  381.      * <p><b>"Experimental - subject to change"</b></p>
  382.      *
  383.      * @param namespaceURI The <em>namespace URI</em> of
  384.      *   the element to create.
  385.      * @param qualifiedName The <em>qualified name</em>
  386.      *   of the element type to instantiate.
  387.      * @return A new <code>IDOM_Element</code> object.
  388.      * @exception IDOMException
  389.      *   INVALID_CHARACTER_ERR: Raised if the specified qualified name contains
  390.      *                          an illegal character.
  391.      * <br>
  392.      *   NAMESPACE_ERR: Raised if the <CODE>qualifiedName</CODE> is
  393.      *      malformed, if the <CODE>qualifiedName</CODE> has a prefix and the
  394.      *      <CODE>namespaceURI</CODE> is <CODE>null</CODE> or an empty string,
  395.      *      or if the <CODE>qualifiedName</CODE> has a prefix that is "xml" and
  396.      *      the <CODE>namespaceURI</CODE> is different from
  397.      *      "http://www.w3.org/XML/1998/namespace".
  398.      */
  399.     virtual IDOM_Element         *createElementNS(const XMLCh *namespaceURI,
  400.                                               const XMLCh *qualifiedName) = 0;
  401.     /**
  402.      * Creates an attribute of the given qualified name and namespace
  403.      * URI.
  404.      *
  405.      * <p><b>"Experimental - subject to change"</b></p>
  406.      *
  407.      * @param namespaceURI The <em>namespace URI</em> of
  408.      *   the attribute to create.
  409.      * @param qualifiedName The <em>qualified name</em>
  410.      *   of the attribute to instantiate.
  411.      * @return A new <code>IDOM_Attr</code> object.
  412.      * @exception IDOMException
  413.      *   INVALID_CHARACTER_ERR: Raised if the specified qualified name contains
  414.      *                          an illegal character.
  415.      * <br>
  416.      *   NAMESPACE_ERR: Raised if the <CODE>qualifiedName</CODE> is
  417.      *      malformed, if the <CODE>qualifiedName</CODE> has a prefix and the
  418.      *      <CODE>namespaceURI</CODE> is <CODE>null</CODE> or an empty string,
  419.      *      if the <CODE>qualifiedName</CODE> has a prefix that is "xml" and the
  420.      *      <CODE>namespaceURI</CODE> is different from
  421.      *      "http://www.w3.org/XML/1998/namespace", if the
  422.      *      <CODE>qualifiedName</CODE> has a prefix that is "xmlns" and the
  423.      *      <CODE>namespaceURI</CODE> is different from
  424.      *      "http://www.w3.org/2000/xmlns/", or if the
  425.      *      <CODE>qualifiedName</CODE> is "xmlns" and the
  426.      *      <CODE>namespaceURI</CODE> is different from
  427.      *      "http://www.w3.org/2000/xmlns/".
  428.      */
  429.     virtual IDOM_Attr        *createAttributeNS(const XMLCh *namespaceURI,
  430.                                             const XMLCh *qualifiedName) = 0;
  431.     /**
  432.      * Returns a <code>IDOM_NodeList</code> of all the <code>IDOM_Element</code>s
  433.      * with a given <em>local name</em> and
  434.      * namespace URI in the order in which they would be encountered in a
  435.      * preorder traversal of the <code>IDOM_Document</code> tree.
  436.      *
  437.      * <p><b>"Experimental - subject to change"</b></p>
  438.      *
  439.      * @param namespaceURI The <em>namespace URI</em> of
  440.      *   the elements to match on. The special value "*" matches all
  441.      *   namespaces.
  442.      * @param localName The <em>local name</em> of the
  443.      *   elements to match on. The special value "*" matches all local names.
  444.      * @return A new <code>IDOM_NodeList</code> object containing all the matched
  445.      *  <code>IDOM_Element</code>s.
  446.      */
  447.     virtual IDOM_NodeList        *getElementsByTagNameNS(const XMLCh *namespaceURI,
  448.                                                      const XMLCh *localName) const = 0;
  449.     /**
  450.      * Returns the <code>IDOM_Element</code> whose ID is given by <code>elementId</code>.
  451.      * If no such element exists, returns <code>null</code>.
  452.      * Behavior is not defined if more than one element has this <code>ID</code>.
  453.      * <P><B>Note:</B> The IDOM implementation must have information that says
  454.      * which attributes are of type ID. Attributes with the name "ID" are not of
  455.      * type ID unless so defined. Implementations that do not know whether
  456.      * attributes are of type ID or not are expected to return
  457.      * <CODE>null</CODE>.</P>
  458.      *
  459.      * <p><b>"Experimental - subject to change"</b></p>
  460.      *
  461.      * @param elementId The unique <code>id</code> value for an element.
  462.      * @return The matching element.
  463.      */
  464.     virtual  IDOM_Element        * getElementById(const XMLCh *elementId) const = 0;
  465.     //@}
  466. protected:
  467.     friend class IDOM_Node;
  468.     friend class DocumentImpl;
  469.     friend class NodeIteratorImpl;
  470.     friend class IDOM_IDOMImplementation;
  471. };
  472. #endif