| 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.16 2003/01/03 20:09:36 tng Exp $
    00059  *
    00060  */
    00061 #if !defined(ABSTRACTDOMPARSER_HPP)
    00062 #define ABSTRACTDOMPARSER_HPP
    00063
    00064 #include <xercesc/dom/DOMDocument.hpp>
    00065 #include <xercesc/framework/XMLDocumentHandler.hpp>
    00066 #include <xercesc/framework/XMLErrorReporter.hpp>
    00067 #include <xercesc/framework/XMLEntityHandler.hpp>
    00068 #include <xercesc/util/ValueStackOf.hpp>
    00069 #include <xercesc/validators/DTD/DocTypeHandler.hpp>
    00070 #include <xercesc/dom/DOMDocumentType.hpp>
    00071 #include <xercesc/validators/DTD/DTDElementDecl.hpp>
    00072 #include <xercesc/framework/XMLBufferMgr.hpp>
    00073
    00074
    00075 XERCES_CPP_NAMESPACE_BEGIN
    00076
    00077 class XMLPScanToken;
    00078 class XMLScanner;
    00079 class XMLValidator;
    00080 class DOMDocumentImpl;
    00081 class DOMDocumentTypeImpl;
    00082 class DOMElement;
    00083 class GrammarResolver;
    00084
    00085
    00090 class  AbstractDOMParser :
    00091
    00092     public XMLDocumentHandler
    00093     , public XMLErrorReporter
    00094     , public XMLEntityHandler
    00095     , public DocTypeHandler
    00096 {
    00097 public :
    00098     // -----------------------------------------------------------------------
    00099     //  Class types
    00100     // -----------------------------------------------------------------------
    00103
    00111     enum ValSchemes
    00112     {
    00113         Val_Never
    00114         , Val_Always
    00115         , Val_Auto
    00116     };
    00118
    00119
    00120     // -----------------------------------------------------------------------
    00121     //  Constructors and Detructor
    00122     // -----------------------------------------------------------------------
    00125
    00129     virtual ~AbstractDOMParser();
    00130
    00132
    00133     // -----------------------------------------------------------------------
    00134     //  Utility methods
    00135     // -----------------------------------------------------------------------
    00136
    00144     void reset();
    00145
    00159     DOMDocument* adoptDocument();
    00160
    00162
    00163
    00164     // -----------------------------------------------------------------------
    00165     //  Getter methods
    00166     // -----------------------------------------------------------------------
    00167
    00170
    00182     DOMDocument* getDocument();
    00183
    00191     const XMLValidator& getValidator() const;
    00192
    00200     ValSchemes getValidationScheme() const;
    00201
    00212     bool getDoSchema() const;
    00213
    00224     bool getValidationSchemaFullChecking() const;
    00225
    00237     int getErrorCount() const;
    00238
    00249     bool getDoNamespaces() const;
    00250
    00263     bool getExitOnFirstFatalError() const;
    00264
    00275     bool getValidationConstraintFatal() const;
    00276
    00286     bool  getCreateEntityReferenceNodes()const;
    00287
    00298     bool getIncludeIgnorableWhitespace() const;
    00299
    00319     XMLCh* getExternalSchemaLocation() const;
    00320
    00340     XMLCh* getExternalNoNamespaceSchemaLocation() const;
    00341
    00353     bool getLoadExternalDTD() const;
    00354
    00363     bool  getCreateCommentNodes()const;
    00364
    00376     bool getCalculateSrcOfs() const;
    00377
    00388     bool getStandardUriConformant() const;
    00389
    00391
    00392
    00393     // -----------------------------------------------------------------------
    00394     //  Setter methods
    00395     // -----------------------------------------------------------------------
    00396
    00399
    00414     void setDoNamespaces(const bool newState);
    00415
    00432     void setExitOnFirstFatalError(const bool newState);
    00433
    00453     void setValidationConstraintFatal(const bool newState);
    00454
    00473     void setCreateEntityReferenceNodes(const bool create);
    00474
    00496     void setIncludeIgnorableWhitespace(const bool include);
    00497
    00514     void setValidationScheme(const ValSchemes newScheme);
    00515
    00531     void setDoSchema(const bool newState);
    00532
    00549     void setValidationSchemaFullChecking(const bool schemaFullChecking);
    00550
    00571     void setExternalSchemaLocation(const XMLCh* const schemaLocation);
    00572
    00581     void setExternalSchemaLocation(const char* const schemaLocation);
    00582
    00597     void setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation);
    00598
    00607     void setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation);
    00608
    00625     void setLoadExternalDTD(const bool newState);
    00626
    00637     void setCreateCommentNodes(const bool create);
    00638
    00651     void setCalculateSrcOfs(const bool newState);
    00652
    00663     void setStandardUriConformant(const bool newState);
    00664
    00672     void useScanner(const XMLCh* const scannerName);
    00673
    00675
    00676
    00677     // -----------------------------------------------------------------------
    00678     //  Parsing methods
    00679     // -----------------------------------------------------------------------
    00680
    00683
    00699     void parse(const InputSource& source);
    00700
    00717     void parse(const XMLCh* const systemId);
    00718
    00734     void parse(const char* const systemId);
    00735
    00762     bool parseFirst
    00763     (
    00764         const   XMLCh* const    systemId
    00765         ,       XMLPScanToken&  toFill
    00766     );
    00767
    00795     bool parseFirst
    00796     (
    00797         const   char* const     systemId
    00798         ,       XMLPScanToken&  toFill
    00799     );
    00800
    00828     bool parseFirst
    00829     (
    00830         const   InputSource&    source
    00831         ,       XMLPScanToken&  toFill
    00832     );
    00833
    00856     bool parseNext(XMLPScanToken& token);
    00857
    00883     void parseReset(XMLPScanToken& token);
    00884
    00886
    00887     // -----------------------------------------------------------------------
    00888     //  Implementation of the XMLDocumentHandler interface.
    00889     // -----------------------------------------------------------------------
    00890
    00893
    00906     virtual void docCharacters
    00907     (
    00908         const   XMLCh* const    chars
    00909         , const unsigned int    length
    00910         , const bool            cdataSection
    00911     );
    00912
    00921     virtual void docComment
    00922     (
    00923         const   XMLCh* const    comment
    00924     );
    00925
    00938     virtual void docPI
    00939     (
    00940         const   XMLCh* const    target
    00941         , const XMLCh* const    data
    00942     );
    00943
    00948     virtual void endDocument();
    00949
    00966     virtual void endElement
    00967     (
    00968         const   XMLElementDecl& elemDecl
    00969         , const unsigned int    urlId
    00970         , const bool            isRoot
    00971         , const XMLCh* const    elemPrefix
    00972     );
    00973
    00982     virtual void endEntityReference
    00983     (
    00984         const   XMLEntityDecl&  entDecl
    00985     );
    00986
    01005     virtual void ignorableWhitespace
    01006     (
    01007         const   XMLCh* const    chars
    01008         , const unsigned int    length
    01009         , const bool            cdataSection
    01010     );
    01011
    01018     virtual void resetDocument();
    01019
    01024     virtual void startDocument();
    01025
    01053     virtual void startElement
    01054     (
    01055         const   XMLElementDecl&         elemDecl
    01056         , const unsigned int            urlId
    01057         , const XMLCh* const            elemPrefix
    01058         , const RefVectorOf<XMLAttr>&   attrList
    01059         , const unsigned int            attrCount
    01060         , const bool                    isEmpty
    01061         , const bool                    isRoot
    01062     );
    01063
    01073     virtual void startEntityReference
    01074     (
    01075         const   XMLEntityDecl&  entDecl
    01076     );
    01077
    01096     virtual void XMLDecl
    01097     (
    01098         const   XMLCh* const    versionStr
    01099         , const XMLCh* const    encodingStr
    01100         , const XMLCh* const    standaloneStr
    01101         , const XMLCh* const    actualEncStr
    01102     );
    01104
    01105
    01106     // -----------------------------------------------------------------------
    01107     //  Implementation of the deprecated DocTypeHandler interface.
    01108     // -----------------------------------------------------------------------
    01111     virtual void attDef
    01112     (
    01113         const   DTDElementDecl&     elemDecl
    01114         , const DTDAttDef&          attDef
    01115         , const bool                ignoring
    01116     );
    01117
    01118     virtual void doctypeComment
    01119     (
    01120         const   XMLCh* const    comment
    01121     );
    01122
    01123     virtual void doctypeDecl
    01124     (
    01125         const   DTDElementDecl& elemDecl
    01126         , const XMLCh* const    publicId
    01127         , const XMLCh* const    systemId
    01128         , const bool            hasIntSubset
    01129         , const bool            hasExtSubset = false
    01130     );
    01131
    01132     virtual void doctypePI
    01133     (
    01134         const   XMLCh* const    target
    01135         , const XMLCh* const    data
    01136     );
    01137
    01138     virtual void doctypeWhitespace
    01139     (
    01140         const   XMLCh* const    chars
    01141         , const unsigned int    length
    01142     );
    01143
    01144     virtual void elementDecl
    01145     (
    01146         const   DTDElementDecl& decl
    01147         , const bool            isIgnored
    01148     );
    01149
    01150     virtual void endAttList
    01151     (
    01152         const   DTDElementDecl& elemDecl
    01153     );
    01154
    01155     virtual void endIntSubset();
    01156
    01157     virtual void endExtSubset();
    01158
    01159     virtual void entityDecl
    01160     (
    01161         const   DTDEntityDecl&  entityDecl
    01162         , const bool            isPEDecl
    01163         , const bool            isIgnored
    01164     );
    01165
    01166     virtual void resetDocType();
    01167
    01168     virtual void notationDecl
    01169     (
    01170         const   XMLNotationDecl&    notDecl
    01171         , const bool                isIgnored
    01172     );
    01173
    01174     virtual void startAttList
    01175     (
    01176         const   DTDElementDecl& elemDecl
    01177     );
    01178
    01179     virtual void startIntSubset();
    01180
    01181     virtual void startExtSubset();
    01182
    01183     virtual void TextDecl
    01184     (
    01185         const   XMLCh* const    versionStr
    01186         , const XMLCh* const    encodingStr
    01187     );
    01188
    01189
    01191
    01192
    01193     // -----------------------------------------------------------------------
    01194     //  Deprecated Methods
    01195     // -----------------------------------------------------------------------
    01208     bool getDoValidation() const;
    01209
    01223     void setDoValidation(const bool newState);
    01224
    01238     bool getExpandEntityReferences() const;
    01239
    01256     void setExpandEntityReferences(const bool expand);
    01257
    01259
    01260 protected :
    01261     // -----------------------------------------------------------------------
    01262     //  Protected Constructor Methods
    01263     // -----------------------------------------------------------------------
    01275     AbstractDOMParser(XMLValidator* const valToAdopt = 0);
    01276
    01278
    01279     // -----------------------------------------------------------------------
    01280     //  Protected getter methods
    01281     // -----------------------------------------------------------------------
    01289     DOMNode* getCurrentNode();
    01290
    01295     XMLScanner* getScanner() const;
    01296
    01301     GrammarResolver* getGrammarResolver() const;
    01302
    01308     bool getParseInProgress() const;
    01309
    01311
    01312
    01313     // -----------------------------------------------------------------------
    01314     //  Protected setter methods
    01315     // -----------------------------------------------------------------------
    01316
    01319
    01327     void setCurrentNode(DOMNode* toSet);
    01328
    01335     void setDocument(DOMDocument* toSet);
    01336
    01343     void setParseInProgress(const bool toSet);
    01345
    01346     // -----------------------------------------------------------------------
    01347     //  Protected Helper methods
    01348     // -----------------------------------------------------------------------
    01351     virtual DOMElement* createElementNSNode(const XMLCh *fNamespaceURI,
    01352                                               const XMLCh *qualifiedName);
    01353
    01354     void resetPool();
    01355
    01359     bool isDocumentAdopted() const;
    01360
    01362
    01363
    01364 private :
    01365     // -----------------------------------------------------------------------
    01366     //  Initialize/Cleanup methods
    01367     // -----------------------------------------------------------------------
    01368     void initialize();
    01369     void cleanUp();
    01370
    01371     // -----------------------------------------------------------------------
    01372     //  Private data members
    01373     //
    01374     //  fCurrentNode
    01375     //  fCurrentParent
    01376     //      Used to track the current node during nested element events. Since
    01377     //      the tree must be built from a set of disjoint callbacks, we need
    01378     //      these to keep up with where we currently are.
    01379     //
    01380     //  fCurrentEntity
    01381     //      Used to track the current entity decl.  If a text decl is seen later on,
    01382     //      it is used to update the encoding and version information.
    01383     //
    01384     //  fDocument
    01385     //      The root document object, filled with the document contents.
    01386     //
    01387     //  fCreateEntityReferenceNodes
    01388     //      Indicates whether entity reference nodes should be created.
    01389     //
    01390     //  fIncludeIgnorableWhitespace
    01391     //      Indicates whether ignorable whiltespace should be added to
    01392     //      the DOM tree for validating parsers.
    01393     //
    01394     //  fScanner
    01395     //      The scanner used for this parser. This is created during the
    01396     //      constructor.
    01397     //
    01398     //  fNodeStack
    01399     //      Used to track previous parent nodes during nested element events.
    01400     //
    01401     //  fParseInProgress
    01402     //      Used to prevent multiple entrance to the parser while its doing
    01403     //      a parse.
    01404     //
    01405     //  fWithinElement
    01406     //      A flag to indicate that the parser is within at least one level
    01407     //      of element processing.
    01408     //
    01409     //  fDocumentType
    01410     //      Used to store and update the documentType variable information
    01411     //      in fDocument
    01412     //
    01413     //  fDocumentVector
    01414     //      Store all the previous fDocument(s) (thus not the current fDocument)
    01415     //      created in this parser.  It is destroyed when the parser is destructed.
    01416     //
    01417     //  fCreateCommentNodes
    01418     //      Indicates whether comment nodes should be created.
    01419     //
    01420     //  fDocumentAdoptedByUser
    01421     //      The DOMDocument ownership has been transferred to application
    01422     //      If set to true, the parser does not own the document anymore
    01423     //      and thus will not release its memory.
    01424     //
    01425     //  fInternalSubset
    01426     //      Buffer for storing the internal subset information.
    01427     //      Once complete (after DOCTYPE is finished scanning), send
    01428     //      it to DocumentType Node
    01429     // -----------------------------------------------------------------------
    01430     bool                          fCreateEntityReferenceNodes;
    01431     bool                          fIncludeIgnorableWhitespace;
    01432     bool                          fWithinElement;
    01433     bool                          fParseInProgress;
    01434     bool                          fCreateCommentNodes;
    01435     bool                          fDocumentAdoptedByUser;
    01436     XMLBufferMgr                  fBufMgr;
    01437     XMLScanner*                   fScanner;
    01438     DOMNode*                      fCurrentParent;
    01439     DOMNode*                      fCurrentNode;
    01440     DOMEntity*                    fCurrentEntity;
    01441     DOMDocumentImpl*              fDocument;
    01442     ValueStackOf<DOMNode*>*       fNodeStack;
    01443     DOMDocumentTypeImpl*          fDocumentType;
    01444     RefVectorOf<DOMDocumentImpl>* fDocumentVector;
    01445     GrammarResolver*              fGrammarResolver;
    01446     XMLStringPool*                fURIStringPool;
    01447     XMLValidator*                 fValidator;
    01448     XMLBuffer&                    fInternalSubset;
    01449 };
    01450
    01451
    01452
    01453 // ---------------------------------------------------------------------------
    01454 //  AbstractDOMParser: Getter methods
    01455 // ---------------------------------------------------------------------------
    01456 inline bool AbstractDOMParser::getExpandEntityReferences() const
    01457 {
    01458     return !fCreateEntityReferenceNodes;
    01459 }
    01460 inline bool AbstractDOMParser::getCreateEntityReferenceNodes() const
    01461 {
    01462     return fCreateEntityReferenceNodes;
    01463 }
    01464
    01465 inline bool AbstractDOMParser::getIncludeIgnorableWhitespace() const
    01466 {
    01467     return fIncludeIgnorableWhitespace;
    01468 }
    01469
    01470 inline bool AbstractDOMParser::getParseInProgress() const
    01471 {
    01472     return fParseInProgress;
    01473 }
    01474
    01475 inline XMLScanner* AbstractDOMParser::getScanner() const
    01476 {
    01477     return fScanner;
    01478 }
    01479
    01480 inline GrammarResolver* AbstractDOMParser::getGrammarResolver() const
    01481 {
    01482     return fGrammarResolver;
    01483 }
    01484
    01485 inline bool AbstractDOMParser::getCreateCommentNodes() const
    01486 {
    01487     return fCreateCommentNodes;
    01488 }
    01489
    01490 // ---------------------------------------------------------------------------
    01491 //  AbstractDOMParser: Setter methods
    01492 // ---------------------------------------------------------------------------
    01493 inline void AbstractDOMParser::setExpandEntityReferences(const bool expand)
    01494 {
    01495     fCreateEntityReferenceNodes = !expand;
    01496 }
    01497
    01498 inline void AbstractDOMParser::setCreateEntityReferenceNodes(const bool create)
    01499 {
    01500     fCreateEntityReferenceNodes = create;
    01501 }
    01502
    01503 inline void AbstractDOMParser::setIncludeIgnorableWhitespace(const bool include)
    01504 {
    01505     fIncludeIgnorableWhitespace = include;
    01506 }
    01507
    01508 inline void AbstractDOMParser::setCreateCommentNodes(const bool create)
    01509 {
    01510     fCreateCommentNodes = create;
    01511 }
    01512
    01513
    01514 // ---------------------------------------------------------------------------
    01515 //  AbstractDOMParser: Protected getter methods
    01516 // ---------------------------------------------------------------------------
    01517 inline DOMNode* AbstractDOMParser::getCurrentNode()
    01518 {
    01519     return fCurrentNode;
    01520 }
    01521
    01522
    01523 // ---------------------------------------------------------------------------
    01524 //  AbstractDOMParser: Protected setter methods
    01525 // ---------------------------------------------------------------------------
    01526 inline void AbstractDOMParser::setCurrentNode(DOMNode* toSet)
    01527 {
    01528     fCurrentNode = toSet;
    01529 }
    01530
    01531 inline void AbstractDOMParser::setDocument(DOMDocument* toSet)
    01532 {
    01533     fDocument = (DOMDocumentImpl *)toSet;
    01534 }
    01535
    01536 inline void AbstractDOMParser::setParseInProgress(const bool toSet)
    01537 {
    01538     fParseInProgress = toSet;
    01539 }
    01540
    01541 XERCES_CPP_NAMESPACE_END
    01542
    01543 #endif
    01544
    01545
    01546

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