http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Home

Readme
Release Info

Installation
Download
Build

FAQs
Samples
API Docs

DOM C++ Binding
Programming
Migration Guide

Feedback
Bug-Reporting
PDF Document

CVS Repository
Mail Archive

API Docs for SAX and DOM
 

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

AbstractDOMParser.hpp

Go to the documentation of this file.
00001 /*
00002  * The Apache Software License, Version 1.1
00003  *
00004  * Copyright (c) 2002 The Apache Software Foundation.  All rights
00005  * reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  *
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in
00016  *    the documentation and/or other materials provided with the
00017  *    distribution.
00018  *
00019  * 3. The end-user documentation included with the redistribution,
00020  *    if any, must include the following acknowledgment:
00021  *       "This product includes software developed by the
00022  *        Apache Software Foundation (http://www.apache.org/)."
00023  *    Alternately, this acknowledgment may appear in the software itself,
00024  *    if and wherever such third-party acknowledgments normally appear.
00025  *
00026  * 4. The names "Xerces" and "Apache Software Foundation" must
00027  *    not be used to endorse or promote products derived from this
00028  *    software without prior written permission. For written
00029  *    permission, please contact apache\@apache.org.
00030  *
00031  * 5. Products derived from this software may not be called "Apache",
00032  *    nor may "Apache" appear in their name, without prior written
00033  *    permission of the Apache Software Foundation.
00034  *
00035  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00036  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00037  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00038  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00039  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00040  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00041  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00042  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00043  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00044  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00045  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00046  * SUCH DAMAGE.
00047  * ====================================================================
00048  *
00049  * This software consists of voluntary contributions made by many
00050  * individuals on behalf of the Apache Software Foundation, and was
00051  * originally based on software copyright (c) 2001, International
00052  * Business Machines, Inc., http://www.ibm.com .  For more information
00053  * on the Apache Software Foundation, please see
00054  * <http://www.apache.org/>.
00055  */
00056 
00057 /*
00058  * $Id: AbstractDOMParser.hpp,v 1.9 2002/07/11 18:27:20 knoaman Exp $
00059  *
00060  */
00061 #if !defined(ABSTRACTDOMPARSER_HPP)
00062 #define ABSTRACTDOMPARSER_HPP
00063 
00064 
00065 #include <xercesc/dom/DOMDocument.hpp>
00066 #include <xercesc/framework/XMLDocumentHandler.hpp>
00067 #include <xercesc/framework/XMLErrorReporter.hpp>
00068 #include <xercesc/framework/XMLEntityHandler.hpp>
00069 #include <xercesc/util/ValueStackOf.hpp>
00070 #include <xercesc/validators/DTD/DocTypeHandler.hpp>
00071 #include <xercesc/dom/DOMDocumentType.hpp>
00072 #include <xercesc/validators/DTD/DTDElementDecl.hpp>
00073 #include <xercesc/framework/XMLBufferMgr.hpp>
00074 
00075 class XMLPScanToken;
00076 class XMLScanner;
00077 class XMLValidator;
00078 class DOMDocumentImpl;
00079 class DOMDocumentTypeImpl;
00080 class DOMElement;
00081 
00082 
00087 class  AbstractDOMParser :
00088 
00089     public XMLDocumentHandler
00090     , public XMLErrorReporter
00091     , public XMLEntityHandler
00092     , public DocTypeHandler
00093 {
00094 public :
00095     // -----------------------------------------------------------------------
00096     //  Class types
00097     // -----------------------------------------------------------------------
00100 
00108     enum ValSchemes
00109     {
00110         Val_Never
00111         , Val_Always
00112         , Val_Auto
00113     };
00115 
00116 
00117     // -----------------------------------------------------------------------
00118     //  Constructors and Detructor
00119     // -----------------------------------------------------------------------
00122 
00126     virtual ~AbstractDOMParser();
00127 
00129 
00130     // -----------------------------------------------------------------------
00131     //  Utility methods
00132     // -----------------------------------------------------------------------
00133 
00136 
00141     void reset();
00142 
00156     DOMDocument* adoptDocument();
00157 
00159 
00160 
00161     // -----------------------------------------------------------------------
00162     //  Getter methods
00163     // -----------------------------------------------------------------------
00164 
00167 
00179     DOMDocument* getDocument();
00180 
00188     const XMLValidator& getValidator() const;
00189 
00197     ValSchemes getValidationScheme() const;
00198 
00209     bool getDoSchema() const;
00210 
00221     bool getValidationSchemaFullChecking() const;
00222 
00234     int getErrorCount() const;
00235 
00246     bool getDoNamespaces() const;
00247 
00260     bool getExitOnFirstFatalError() const;
00261 
00272     bool getValidationConstraintFatal() const;
00273 
00283     bool  getCreateEntityReferenceNodes()const;
00284 
00295     bool getIncludeIgnorableWhitespace() const;
00296 
00316     XMLCh* getExternalSchemaLocation() const;
00317 
00337     XMLCh* getExternalNoNamespaceSchemaLocation() const;
00338 
00350     bool getLoadExternalDTD() const;
00351 
00360     bool  getCreateCommentNodes()const;
00361 
00363 
00364 
00365     // -----------------------------------------------------------------------
00366     //  Setter methods
00367     // -----------------------------------------------------------------------
00368 
00371 
00386     void setDoNamespaces(const bool newState);
00387 
00404     void setExitOnFirstFatalError(const bool newState);
00405 
00425     void setValidationConstraintFatal(const bool newState);
00426 
00445     void setCreateEntityReferenceNodes(const bool create);
00446 
00468     void setIncludeIgnorableWhitespace(const bool include);
00469 
00486     void setValidationScheme(const ValSchemes newScheme);
00487 
00503     void setDoSchema(const bool newState);
00504 
00521     void setValidationSchemaFullChecking(const bool schemaFullChecking);
00522 
00542 
00543     void setExternalSchemaLocation(const XMLCh* const schemaLocation);
00544 
00553     void setExternalSchemaLocation(const char* const schemaLocation);
00554 
00569     void setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation);
00570 
00579     void setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation);
00580 
00597     void setLoadExternalDTD(const bool newState);
00598 
00609     void setCreateCommentNodes(const bool create);
00610 
00612 
00613 
00614     // -----------------------------------------------------------------------
00615     //  Parsing methods
00616     // -----------------------------------------------------------------------
00617 
00620 
00636     void parse(const InputSource& source);
00637 
00654     void parse(const XMLCh* const systemId);
00655 
00671     void parse(const char* const systemId);
00672 
00699     bool parseFirst
00700     (
00701         const   XMLCh* const    systemId
00702         ,       XMLPScanToken&  toFill
00703     );
00704 
00732     bool parseFirst
00733     (
00734         const   char* const     systemId
00735         ,       XMLPScanToken&  toFill
00736     );
00737 
00765     bool parseFirst
00766     (
00767         const   InputSource&    source
00768         ,       XMLPScanToken&  toFill
00769     );
00770 
00793     bool parseNext(XMLPScanToken& token);
00794 
00820     void parseReset(XMLPScanToken& token);
00821 
00823 
00824     // -----------------------------------------------------------------------
00825     //  Implementation of the XMLDocumentHandler interface.
00826     // -----------------------------------------------------------------------
00827 
00830 
00843     virtual void docCharacters
00844     (
00845         const   XMLCh* const    chars
00846         , const unsigned int    length
00847         , const bool            cdataSection
00848     );
00849 
00858     virtual void docComment
00859     (
00860         const   XMLCh* const    comment
00861     );
00862 
00875     virtual void docPI
00876     (
00877         const   XMLCh* const    target
00878         , const XMLCh* const    data
00879     );
00880 
00885     virtual void endDocument();
00886 
00903     virtual void endElement
00904     (
00905         const   XMLElementDecl& elemDecl
00906         , const unsigned int    urlId
00907         , const bool            isRoot
00908         , const XMLCh* const    elemPrefix
00909     );
00910 
00919     virtual void endEntityReference
00920     (
00921         const   XMLEntityDecl&  entDecl
00922     );
00923 
00942     virtual void ignorableWhitespace
00943     (
00944         const   XMLCh* const    chars
00945         , const unsigned int    length
00946         , const bool            cdataSection
00947     );
00948 
00955     virtual void resetDocument();
00956 
00961     virtual void startDocument();
00962 
00990     virtual void startElement
00991     (
00992         const   XMLElementDecl&         elemDecl
00993         , const unsigned int            urlId
00994         , const XMLCh* const            elemPrefix
00995         , const RefVectorOf<XMLAttr>&   attrList
00996         , const unsigned int            attrCount
00997         , const bool                    isEmpty
00998         , const bool                    isRoot
00999     );
01000 
01010     virtual void startEntityReference
01011     (
01012         const   XMLEntityDecl&  entDecl
01013     );
01014 
01033     virtual void XMLDecl
01034     (
01035         const   XMLCh* const    versionStr
01036         , const XMLCh* const    encodingStr
01037         , const XMLCh* const    standaloneStr
01038         , const XMLCh* const    actualEncStr
01039     );
01041 
01042 
01043     // -----------------------------------------------------------------------
01044     //  Implementation of the deprecated DocTypeHandler interface.
01045     // -----------------------------------------------------------------------
01048     virtual void attDef
01049     (
01050         const   DTDElementDecl&     elemDecl
01051         , const DTDAttDef&          attDef
01052         , const bool                ignoring
01053     );
01054 
01055     virtual void doctypeComment
01056     (
01057         const   XMLCh* const    comment
01058     );
01059 
01060     virtual void doctypeDecl
01061     (
01062         const   DTDElementDecl& elemDecl
01063         , const XMLCh* const    publicId
01064         , const XMLCh* const    systemId
01065         , const bool            hasIntSubset
01066     );
01067 
01068     virtual void doctypePI
01069     (
01070         const   XMLCh* const    target
01071         , const XMLCh* const    data
01072     );
01073 
01074     virtual void doctypeWhitespace
01075     (
01076         const   XMLCh* const    chars
01077         , const unsigned int    length
01078     );
01079 
01080     virtual void elementDecl
01081     (
01082         const   DTDElementDecl& decl
01083         , const bool            isIgnored
01084     );
01085 
01086     virtual void endAttList
01087     (
01088         const   DTDElementDecl& elemDecl
01089     );
01090 
01091     virtual void endIntSubset();
01092 
01093     virtual void endExtSubset();
01094 
01095     virtual void entityDecl
01096     (
01097         const   DTDEntityDecl&  entityDecl
01098         , const bool            isPEDecl
01099         , const bool            isIgnored
01100     );
01101 
01102     virtual void resetDocType();
01103 
01104     virtual void notationDecl
01105     (
01106         const   XMLNotationDecl&    notDecl
01107         , const bool                isIgnored
01108     );
01109 
01110     virtual void startAttList
01111     (
01112         const   DTDElementDecl& elemDecl
01113     );
01114 
01115     virtual void startIntSubset();
01116 
01117     virtual void startExtSubset();
01118 
01119     virtual void TextDecl
01120     (
01121         const   XMLCh* const    versionStr
01122         , const XMLCh* const    encodingStr
01123     );
01124 
01125 
01127 
01128 
01129     // -----------------------------------------------------------------------
01130     //  Deprecated Methods
01131     // -----------------------------------------------------------------------
01134 
01144     bool getDoValidation() const;
01145 
01159     void setDoValidation(const bool newState);
01160 
01174     bool getExpandEntityReferences() const;
01175 
01192     void setExpandEntityReferences(const bool expand);
01193 
01195 
01196 protected :
01197     // -----------------------------------------------------------------------
01198     //  Protected Constructor Methods
01199     // -----------------------------------------------------------------------
01202     /** Construct a AbstractDOMParser, with an optional validator
01203       *
01204       * Constructor with an instance of validator class to use for
01205       * validation. If you don't provide a validator, a default one will
01206       * be created for you in the scanner.
01207       *
01208       * @param valToAdopt Pointer to the validator instance to use. The
01209       *                   parser is responsible for freeing the memory.
01210       */
01211     AbstractDOMParser(XMLValidator* const valToAdopt = 0);
01212 
01214 
01215     // -----------------------------------------------------------------------
01216     //  Protected getter methods
01217     // -----------------------------------------------------------------------
01220     /** Get the current DOM node
01221       *
01222       * This provides derived classes with access to the current node, i.e.
01223       * the node to which new nodes are being added.
01224       */
01225     DOMNode* getCurrentNode();
01226 
01231     XMLScanner* getScanner() const;
01232 
01238     bool getParseInProgress() const;
01239 
01241 
01242 
01243     // -----------------------------------------------------------------------
01244     //  Protected setter methods
01245     // -----------------------------------------------------------------------
01246 
01249 
01257     void setCurrentNode(DOMNode* toSet);
01258 
01265     void setDocument(DOMDocument* toSet);
01266 
01273     void setParseInProgress(const bool toSet);
01275 
01276     // -----------------------------------------------------------------------
01277     //  Protected Helper methods
01278     // -----------------------------------------------------------------------
01281     virtual DOMElement* createElementNSNode(const XMLCh *fNamespaceURI,
01282                                               const XMLCh *qualifiedName);
01283 
01284     void resetPool();
01286 
01287 
01288 private :
01289     // -----------------------------------------------------------------------
01290     //  Private data members
01291     //
01292     //  fCurrentNode
01293     //  fCurrentParent
01294     //      Used to track the current node during nested element events. Since
01295     //      the tree must be built from a set of disjoint callbacks, we need
01296     //      these to keep up with where we currently are.
01297     //
01298     //  fCurrentEntity
01299     //      Used to track the current entity decl.  If a text decl is seen later on,
01300     //      it is used to update the encoding and version information.
01301     //
01302     //  fDocument
01303     //      The root document object, filled with the document contents.
01304     //
01305     //  fCreateEntityReferenceNodes
01306     //      Indicates whether entity reference nodes should be created.
01307     //
01308     //  fIncludeIgnorableWhitespace
01309     //      Indicates whether ignorable whiltespace should be added to
01310     //      the DOM tree for validating parsers.
01311     //
01312     //  fScanner
01313     //      The scanner used for this parser. This is created during the
01314     //      constructor.
01315     //
01316     //  fNodeStack
01317     //      Used to track previous parent nodes during nested element events.
01318     //
01319     //  fParseInProgress
01320     //      Used to prevent multiple entrance to the parser while its doing
01321     //      a parse.
01322     //
01323     //  fWithinElement
01324     //      A flag to indicate that the parser is within at least one level
01325     //      of element processing.
01326     //
01327     //  fDocumentType
01328     //      Used to store and update the documentType variable information
01329     //      in fDocument
01330     //
01331     //  fDocumentVector
01332     //      Store all the previous fDocument(s) (thus not the current fDocument)
01333     //      created in this parser.  It is destroyed when the parser is destructed.
01334     //
01335     //  fCreateCommentNodes
01336     //      Indicates whether comment nodes should be created.
01337     //
01338     //  fDocumentAdoptedByUser
01339     //      The DOMDocument ownership has been transferred to application
01340     //      If set to true, the parser does not own the document anymore
01341     //      and thus will not release its memory.
01342     // -----------------------------------------------------------------------
01343     bool                          fCreateEntityReferenceNodes;
01344     bool                          fIncludeIgnorableWhitespace;
01345     bool                          fWithinElement;
01346     bool                          fParseInProgress;
01347     XMLBufferMgr                  fBufMgr;
01348     XMLScanner*                   fScanner;
01349     DOMNode*                      fCurrentParent;
01350     DOMNode*                      fCurrentNode;
01351     DOMEntity*                    fCurrentEntity;
01352     DOMDocumentImpl*              fDocument;
01353     ValueStackOf<DOMNode*>*       fNodeStack;
01354     DOMDocumentTypeImpl*          fDocumentType;
01355     RefVectorOf<DOMDocumentImpl>* fDocumentVector;
01356     bool                          fCreateCommentNodes;
01357     bool                          fDocumentAdoptedByUser;
01358 };
01359 
01360 
01361 
01362 // ---------------------------------------------------------------------------
01363 //  AbstractDOMParser: Getter methods
01364 // ---------------------------------------------------------------------------
01365 inline bool AbstractDOMParser::getExpandEntityReferences() const
01366 {
01367     return !fCreateEntityReferenceNodes;
01368 }
01369 inline bool AbstractDOMParser::getCreateEntityReferenceNodes() const
01370 {
01371     return fCreateEntityReferenceNodes;
01372 }
01373 
01374 inline bool AbstractDOMParser::getIncludeIgnorableWhitespace() const
01375 {
01376     return fIncludeIgnorableWhitespace;
01377 }
01378 
01379 inline bool AbstractDOMParser::getParseInProgress() const
01380 {
01381     return fParseInProgress;
01382 }
01383 
01384 inline XMLScanner* AbstractDOMParser::getScanner() const
01385 {
01386     return fScanner;
01387 }
01388 
01389 inline bool AbstractDOMParser::getCreateCommentNodes() const
01390 {
01391     return fCreateCommentNodes;
01392 }
01393 
01394 // ---------------------------------------------------------------------------
01395 //  AbstractDOMParser: Setter methods
01396 // ---------------------------------------------------------------------------
01397 inline void AbstractDOMParser::setExpandEntityReferences(const bool expand)
01398 {
01399     fCreateEntityReferenceNodes = !expand;
01400 }
01401 
01402 inline void AbstractDOMParser::setCreateEntityReferenceNodes(const bool create)
01403 {
01404     fCreateEntityReferenceNodes = create;
01405 }
01406 
01407 inline void AbstractDOMParser::setIncludeIgnorableWhitespace(const bool include)
01408 {
01409     fIncludeIgnorableWhitespace = include;
01410 }
01411 
01412 inline void AbstractDOMParser::setCreateCommentNodes(const bool create)
01413 {
01414     fCreateCommentNodes = create;
01415 }
01416 
01417 
01418 // ---------------------------------------------------------------------------
01419 //  AbstractDOMParser: Protected getter methods
01420 // ---------------------------------------------------------------------------
01421 inline DOMNode* AbstractDOMParser::getCurrentNode()
01422 {
01423     return fCurrentNode;
01424 }
01425 
01426 
01427 // ---------------------------------------------------------------------------
01428 //  AbstractDOMParser: Protected setter methods
01429 // ---------------------------------------------------------------------------
01430 inline void AbstractDOMParser::setCurrentNode(DOMNode* toSet)
01431 {
01432     fCurrentNode = toSet;
01433 }
01434 
01435 inline void AbstractDOMParser::setDocument(DOMDocument* toSet)
01436 {
01437     fDocument = (DOMDocumentImpl *)toSet;
01438 }
01439 
01440 inline void AbstractDOMParser::setParseInProgress(const bool toSet)
01441 {
01442     fParseInProgress = toSet;
01443 }
01444 
01445 #endif
01446 
01447 
01448 


Copyright © 2000 The Apache Software Foundation. All Rights Reserved.