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

Home

Readme
Download
Installation
Build

API Docs
Samples
Schema

FAQs
Programming
Migration

Releases
Bug-Reporting
Feedback

Y2K Compliance
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  

DOMParser.hpp

Go to the documentation of this file.
00001 /*
00002  * The Apache Software License, Version 1.1
00003  *
00004  * Copyright (c) 1999-2001 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) 1999, 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: DOMParser.hpp,v 1.23 2001/06/03 19:26:18 jberry Exp $
00059  *
00060  */
00061 
00062 #if !defined(DOMPARSER_HPP)
00063 #define DOMPARSER_HPP
00064 
00065 
00066 #include <dom/DOM_Document.hpp>
00067 #include <framework/XMLDocumentHandler.hpp>
00068 #include <framework/XMLErrorReporter.hpp>
00069 #include <framework/XMLEntityHandler.hpp>
00070 #include <util/ValueStackOf.hpp>
00071 
00072 #include <validators/DTD/DocTypeHandler.hpp>
00073 #include <dom/DOM_DocumentType.hpp>
00074 #include <validators/DTD/DTDElementDecl.hpp>
00075 
00076 class EntityResolver;
00077 class ErrorHandler;
00078 class XMLPScanToken;
00079 class XMLScanner;
00080 class XMLValidator;
00081 
00082 
00093 class  DOMParser :
00094 
00095     public XMLDocumentHandler
00096     , public XMLErrorReporter
00097     , public XMLEntityHandler
00098     , public DocTypeHandler
00099 {
00100 public :
00101     // -----------------------------------------------------------------------
00102     //  Class types
00103     // -----------------------------------------------------------------------
00104     enum ValSchemes
00105     {
00106         Val_Never
00107         , Val_Always
00108         , Val_Auto
00109     };
00110 
00111 
00112     // -----------------------------------------------------------------------
00113     //  Constructors and Detructor
00114     // -----------------------------------------------------------------------
00115 
00118 
00127     DOMParser(XMLValidator* const valToAdopt = 0);
00128 
00132     ~DOMParser();
00133 
00135 
00141     void reset();
00142 
00143 
00144     // -----------------------------------------------------------------------
00145     //  Getter methods
00146     // -----------------------------------------------------------------------
00147 
00150 
00160     DOM_Document getDocument();
00161 
00169     ErrorHandler* getErrorHandler();
00170 
00178     const ErrorHandler* getErrorHandler() const;
00179 
00187     EntityResolver* getEntityResolver();
00188 
00196     const EntityResolver* getEntityResolver() const;
00197 
00205     const XMLScanner& getScanner() const;
00206 
00214     const XMLValidator& getValidator() const;
00215 
00223     ValSchemes getValidationScheme() const;
00224 
00235     bool getDoSchema() const;
00236 
00248     int getErrorCount() const;
00249 
00260     bool getDoNamespaces() const;
00261 
00274     bool getExitOnFirstFatalError() const;
00275 
00286     bool getValidationConstraintFatal() const;
00287 
00299     bool getExpandEntityReferences() const;
00300 
00318     bool  getCreateEntityReferenceNodes()const;
00319 
00330     bool getIncludeIgnorableWhitespace() const;
00331 
00341     bool getToCreateXMLDeclTypeNode() const;
00342 
00344 
00345 
00346     // -----------------------------------------------------------------------
00347     //  Setter methods
00348     // -----------------------------------------------------------------------
00349 
00352 
00366     void setErrorHandler(ErrorHandler* const handler);
00367 
00383     void setEntityResolver(EntityResolver* const handler);
00384 
00403     void setDoNamespaces(const bool newState);
00404 
00421     void setExitOnFirstFatalError(const bool newState);
00422 
00438     void setValidationConstraintFatal(const bool newState);
00439 
00454     void setExpandEntityReferences(const bool expand);
00455 
00472     void setCreateEntityReferenceNodes(const bool create);
00473 
00495     void setIncludeIgnorableWhitespace(const bool include);
00496 
00513     void setValidationScheme(const ValSchemes newScheme);
00514 
00528     void setDoSchema(const bool newState);
00529 
00540     void setToCreateXMLDeclTypeNode(const bool create);
00541 
00543 
00544 
00545     // -----------------------------------------------------------------------
00546     //  Parsing methods
00547     // -----------------------------------------------------------------------
00548 
00551 
00565     void parse(const InputSource& source, const bool reuseGrammar = false);
00566 
00581     void parse(const XMLCh* const systemId, const bool reuseGrammar = false);
00582 
00594     void parse(const char* const systemId, const bool reuseGrammar = false);
00595 
00625     bool parseFirst
00626     (
00627         const   XMLCh* const    systemId
00628         ,       XMLPScanToken&  toFill
00629         , const bool            reuseGrammar = false
00630     );
00631 
00662     bool parseFirst
00663     (
00664         const   char* const     systemId
00665         ,       XMLPScanToken&  toFill
00666         , const bool            reuseGrammar = false
00667     );
00668 
00699     bool parseFirst
00700     (
00701         const   InputSource&    source
00702         ,       XMLPScanToken&  toFill
00703         , const bool            reuseGrammar = false
00704     );
00705 
00728     bool parseNext(XMLPScanToken& token);
00729 
00755     void parseReset(XMLPScanToken& token);
00756 
00758 
00759 
00760 
00761     // -----------------------------------------------------------------------
00762     //  Implementation of the XMLErrorReporter interface.
00763     // -----------------------------------------------------------------------
00764 
00767 
00792     virtual void error
00793     (
00794         const   unsigned int                errCode
00795         , const XMLCh* const                msgDomain
00796         , const XMLErrorReporter::ErrTypes  errType
00797         , const XMLCh* const                errorText
00798         , const XMLCh* const                systemId
00799         , const XMLCh* const                publicId
00800         , const unsigned int                lineNum
00801         , const unsigned int                colNum
00802     );
00803 
00812     virtual void resetErrors();
00814 
00815 
00816     // -----------------------------------------------------------------------
00817     //  Implementation of the XMLEntityHandler interface.
00818     // -----------------------------------------------------------------------
00819 
00822 
00835     virtual void endInputSource(const InputSource& inputSource);
00836 
00852     virtual bool expandSystemId
00853     (
00854         const   XMLCh* const    systemId
00855         ,       XMLBuffer&      toFill
00856     );
00857 
00866     virtual void resetEntities();
00867 
00883     virtual InputSource* resolveEntity
00884     (
00885         const   XMLCh* const    publicId
00886         , const XMLCh* const    systemId
00887     );
00888 
00901     virtual void startInputSource(const InputSource& inputSource);
00902 
00904 
00905 
00906 
00907     // -----------------------------------------------------------------------
00908     //  Implementation of the XMLDocumentHandler interface.
00909     // -----------------------------------------------------------------------
00910 
00913 
00926     virtual void docCharacters
00927     (
00928         const   XMLCh* const    chars
00929         , const unsigned int    length
00930         , const bool            cdataSection
00931     );
00932 
00941     virtual void docComment
00942     (
00943         const   XMLCh* const    comment
00944     );
00945 
00958     virtual void docPI
00959     (
00960         const   XMLCh* const    target
00961         , const XMLCh* const    data
00962     );
00963 
00968     virtual void endDocument();
00969 
00983     virtual void endElement
00984     (
00985         const   XMLElementDecl& elemDecl
00986         , const unsigned int    urlId
00987         , const bool            isRoot
00988     );
00989 
00998     virtual void endEntityReference
00999     (
01000         const   XMLEntityDecl&  entDecl
01001     );
01002 
01021     virtual void ignorableWhitespace
01022     (
01023         const   XMLCh* const    chars
01024         , const unsigned int    length
01025         , const bool            cdataSection
01026     );
01027 
01034     virtual void resetDocument();
01035 
01040     virtual void startDocument();
01041 
01069     virtual void startElement
01070     (
01071         const   XMLElementDecl&         elemDecl
01072         , const unsigned int            urlId
01073         , const XMLCh* const            elemPrefix
01074         , const RefVectorOf<XMLAttr>&   attrList
01075         , const unsigned int            attrCount
01076         , const bool                    isEmpty
01077         , const bool                    isRoot
01078     );
01079 
01089     virtual void startEntityReference
01090     (
01091         const   XMLEntityDecl&  entDecl
01092     );
01093 
01112     virtual void XMLDecl
01113     (
01114         const   XMLCh* const    versionStr
01115         , const XMLCh* const    encodingStr
01116         , const XMLCh* const    standaloneStr
01117         , const XMLCh* const    actualEncStr
01118     );
01120 
01121 
01124 
01134     bool getDoValidation() const;
01135 
01149     void setDoValidation(const bool newState);
01150 
01154     virtual void attDef
01155     (
01156         const   DTDElementDecl&     elemDecl
01157         , const DTDAttDef&          attDef
01158         , const bool                ignoring
01159     );
01160 
01161     virtual void doctypeComment
01162     (
01163         const   XMLCh* const    comment
01164     );
01165 
01166     virtual void doctypeDecl
01167     (
01168         const   DTDElementDecl& elemDecl
01169         , const XMLCh* const    publicId
01170         , const XMLCh* const    systemId
01171         , const bool            hasIntSubset
01172     );
01173 
01174     virtual void doctypePI
01175     (
01176         const   XMLCh* const    target
01177         , const XMLCh* const    data
01178     );
01179 
01180     virtual void doctypeWhitespace
01181     (
01182         const   XMLCh* const    chars
01183         , const unsigned int    length
01184     );
01185 
01186     virtual void elementDecl
01187     (
01188         const   DTDElementDecl& decl
01189         , const bool            isIgnored
01190     );
01191 
01192     virtual void endAttList
01193     (
01194         const   DTDElementDecl& elemDecl
01195     );
01196 
01197     virtual void endIntSubset();
01198 
01199     virtual void endExtSubset();
01200 
01201     virtual void entityDecl
01202     (
01203         const   DTDEntityDecl&  entityDecl
01204         , const bool            isPEDecl
01205         , const bool            isIgnored
01206     );
01207 
01208     virtual void resetDocType();
01209 
01210     virtual void notationDecl
01211     (
01212         const   XMLNotationDecl&    notDecl
01213         , const bool                isIgnored
01214     );
01215 
01216     virtual void startAttList
01217     (
01218         const   DTDElementDecl& elemDecl
01219     );
01220 
01221     virtual void startIntSubset();
01222 
01223     virtual void startExtSubset();
01224 
01225     virtual void TextDecl
01226     (
01227         const   XMLCh* const    versionStr
01228         , const XMLCh* const    encodingStr
01229     );
01230 
01231 
01233 
01234 
01235 protected :
01236     // -----------------------------------------------------------------------
01237     //  Protected getter methods
01238     // -----------------------------------------------------------------------
01239 
01242 
01247     DOM_Node getCurrentNode();
01248 
01250 
01251 
01252     // -----------------------------------------------------------------------
01253     //  Protected setter methods
01254     // -----------------------------------------------------------------------
01255 
01258 
01266     void setCurrentNode(DOM_Node toSet);
01267 
01274     void setDocument(DOM_Document toSet);
01276 
01277 
01278 private :
01279     // -----------------------------------------------------------------------
01280     //  Private data members
01281     //
01282     //  fCurrentNode
01283     //  fCurrentParent
01284     //      Used to track the current node during nested element events. Since
01285     //      the tree must be built from a set of disjoint callbacks, we need
01286     //      these to keep up with where we currently are.
01287     //
01288     //  fDocument
01289     //      The root document object, filled with the document contents.
01290     //
01291     //  fEntityResolver
01292     //      The installed SAX entity resolver, if any. Null if none.
01293     //
01294     //  fErrorHandler
01295     //      The installed SAX error handler, if any. Null if none.
01296     //
01297     //  fCreateEntityReferenceNode
01298     //      Indicates whether entity reference nodes should be created.
01299     //
01300     //  fIncludeIgnorableWhitespace
01301     //      Indicates whether ignorable whiltespace should be added to
01302     //      the DOM tree for validating parsers.
01303     //
01304     //  fNodeStack
01305     //      Used to track previous parent nodes during nested element events.
01306     //
01307     //  fParseInProgress
01308     //      Used to prevent multiple entrance to the parser while its doing
01309     //      a parse.
01310     //
01311     //  fScanner
01312     //      The scanner used for this parser. This is created during the
01313     //      constructor.
01314     //
01315     //  fWithinElement
01316     //      A flag to indicate that the parser is within at least one level
01317     //      of element processing.
01318     //
01319     //  fDocumentType
01320     //      Used to store and update the documentType variable information
01321     //      in fDocument
01322     //
01323     //  fToCreateXMLDecTypeNode
01324     //      A flag to create a DOM_XMLDecl node in the ODM tree if it exists
01325     //      This is an extension to xerces implementation
01326     //
01327     // -----------------------------------------------------------------------
01328     DOM_Node                fCurrentParent;
01329     DOM_Node                fCurrentNode;
01330     DOM_Document            fDocument;
01331     EntityResolver*         fEntityResolver;
01332     ErrorHandler*           fErrorHandler;
01333     bool                    fCreateEntityReferenceNodes;
01334     bool                    fIncludeIgnorableWhitespace;
01335     ValueStackOf<DOM_Node>* fNodeStack;
01336     bool                    fParseInProgress;
01337     XMLScanner*             fScanner;
01338     bool                    fWithinElement;
01339     DocumentTypeImpl*       fDocumentType;
01340     bool                    fToCreateXMLDeclTypeNode;
01341 };
01342 
01343 
01344 
01345 // ---------------------------------------------------------------------------
01346 //  DOMParser: Handlers for the XMLEntityHandler interface
01347 // ---------------------------------------------------------------------------
01348 inline void DOMParser::endInputSource(const InputSource&)
01349 {
01350     // The DOM entity resolver doesn't handle this
01351 }
01352 
01353 inline bool DOMParser::expandSystemId(const XMLCh* const, XMLBuffer&)
01354 {
01355     // The DOM entity resolver doesn't handle this
01356     return false;
01357 }
01358 
01359 inline void DOMParser::resetEntities()
01360 {
01361     // Nothing to do on this one
01362 }
01363 
01364 inline void DOMParser::startInputSource(const InputSource&)
01365 {
01366     // The DOM entity resolver doesn't handle this
01367 }
01368 
01369 
01370 // ---------------------------------------------------------------------------
01371 //  DOMParser: Getter methods
01372 // ---------------------------------------------------------------------------
01373 inline DOM_Document DOMParser::getDocument()
01374 {
01375     return fDocument;
01376 }
01377 
01378 inline ErrorHandler* DOMParser::getErrorHandler()
01379 {
01380     return fErrorHandler;
01381 }
01382 
01383 inline const ErrorHandler* DOMParser::getErrorHandler() const
01384 {
01385     return fErrorHandler;
01386 }
01387 
01388 inline EntityResolver* DOMParser::getEntityResolver()
01389 {
01390     return fEntityResolver;
01391 }
01392 
01393 inline const EntityResolver* DOMParser::getEntityResolver() const
01394 {
01395     return fEntityResolver;
01396 }
01397 
01398 inline bool DOMParser::getExpandEntityReferences() const
01399 {
01400     return fCreateEntityReferenceNodes;
01401 }
01402 inline bool DOMParser::getCreateEntityReferenceNodes() const
01403 {
01404     return fCreateEntityReferenceNodes;
01405 }
01406 
01407 inline bool DOMParser::getIncludeIgnorableWhitespace() const
01408 {
01409     return fIncludeIgnorableWhitespace;
01410 }
01411 
01412 inline const XMLScanner& DOMParser::getScanner() const
01413 {
01414     return *fScanner;
01415 }
01416 
01417 inline bool DOMParser::getToCreateXMLDeclTypeNode() const
01418 {
01419     return fToCreateXMLDeclTypeNode;
01420 }
01421 
01422 
01423 // ---------------------------------------------------------------------------
01424 //  DOMParser: Setter methods
01425 // ---------------------------------------------------------------------------
01426 inline void DOMParser::setExpandEntityReferences(const bool expand)
01427 {
01428     fCreateEntityReferenceNodes = expand;
01429 }
01430 
01431 inline void DOMParser::setCreateEntityReferenceNodes(const bool create)
01432 {
01433     fCreateEntityReferenceNodes = create;
01434 }
01435 
01436 inline void DOMParser::setIncludeIgnorableWhitespace(const bool include)
01437 {
01438     fIncludeIgnorableWhitespace = include;
01439 }
01440 
01441 inline void DOMParser::setToCreateXMLDeclTypeNode(const bool create)
01442 {
01443     fToCreateXMLDeclTypeNode = create;
01444 }
01445 
01446 
01447 // ---------------------------------------------------------------------------
01448 //  DOMParser: Protected getter methods
01449 // ---------------------------------------------------------------------------
01450 inline DOM_Node DOMParser::getCurrentNode()
01451 {
01452     return fCurrentNode;
01453 }
01454 
01455 
01456 // ---------------------------------------------------------------------------
01457 //  DOMParser: Protected setter methods
01458 // ---------------------------------------------------------------------------
01459 inline void DOMParser::setCurrentNode(DOM_Node toSet)
01460 {
01461     fCurrentNode = toSet;
01462 }
01463 
01464 inline void DOMParser::setDocument(DOM_Document toSet)
01465 {
01466     fDocument = toSet;
01467 }
01468 
01469 #endif


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