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.2 2002/02/20 18:17:01 tng Exp $
00059  *
00060  */
00061 
00062 #if !defined(DOMPARSER_HPP)
00063 #define DOMPARSER_HPP
00064 
00065 
00066 #include <xercesc/dom/DOM_Document.hpp>
00067 #include <xercesc/framework/XMLDocumentHandler.hpp>
00068 #include <xercesc/framework/XMLErrorReporter.hpp>
00069 #include <xercesc/framework/XMLEntityHandler.hpp>
00070 #include <xercesc/util/ValueStackOf.hpp>
00071 
00072 #include <xercesc/validators/DTD/DocTypeHandler.hpp>
00073 #include <xercesc/dom/DOM_DocumentType.hpp>
00074 #include <xercesc/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 
00247     bool getValidationSchemaFullChecking() const;
00248 
00260     int getErrorCount() const;
00261 
00272     bool getDoNamespaces() const;
00273 
00286     bool getExitOnFirstFatalError() const;
00287 
00298     bool getValidationConstraintFatal() const;
00299 
00317     bool  getCreateEntityReferenceNodes()const;
00318 
00329     bool getIncludeIgnorableWhitespace() const;
00330 
00340     bool getToCreateXMLDeclTypeNode() const;
00341 
00361     XMLCh* getExternalSchemaLocation() const;
00362 
00382     XMLCh* getExternalNoNamespaceSchemaLocation() const;
00383 
00385 
00386 
00387     // -----------------------------------------------------------------------
00388     //  Setter methods
00389     // -----------------------------------------------------------------------
00390 
00393 
00407     void setErrorHandler(ErrorHandler* const handler);
00408 
00424     void setEntityResolver(EntityResolver* const handler);
00425 
00444     void setDoNamespaces(const bool newState);
00445 
00462     void setExitOnFirstFatalError(const bool newState);
00463 
00479     void setValidationConstraintFatal(const bool newState);
00480 
00497     void setCreateEntityReferenceNodes(const bool create);
00498 
00520     void setIncludeIgnorableWhitespace(const bool include);
00521 
00538     void setValidationScheme(const ValSchemes newScheme);
00539 
00553     void setDoSchema(const bool newState);
00554 
00571     void setValidationSchemaFullChecking(const bool schemaFullChecking);
00572 
00583     void setToCreateXMLDeclTypeNode(const bool create);
00584 
00604 
00605     void setExternalSchemaLocation(const XMLCh* const schemaLocation);
00606 
00615     void setExternalSchemaLocation(const char* const schemaLocation);
00616 
00631     void setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation);
00632 
00641     void setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation);
00642 
00644 
00645 
00646     // -----------------------------------------------------------------------
00647     //  Parsing methods
00648     // -----------------------------------------------------------------------
00649 
00652 
00673     void parse(const InputSource& source, const bool reuseGrammar = false);
00674 
00694     void parse(const XMLCh* const systemId, const bool reuseGrammar = false);
00695 
00713     void parse(const char* const systemId, const bool reuseGrammar = false);
00714 
00744     bool parseFirst
00745     (
00746         const   XMLCh* const    systemId
00747         ,       XMLPScanToken&  toFill
00748         , const bool            reuseGrammar = false
00749     );
00750 
00781     bool parseFirst
00782     (
00783         const   char* const     systemId
00784         ,       XMLPScanToken&  toFill
00785         , const bool            reuseGrammar = false
00786     );
00787 
00818     bool parseFirst
00819     (
00820         const   InputSource&    source
00821         ,       XMLPScanToken&  toFill
00822         , const bool            reuseGrammar = false
00823     );
00824 
00847     bool parseNext(XMLPScanToken& token);
00848 
00874     void parseReset(XMLPScanToken& token);
00875 
00877 
00878 
00879 
00880     // -----------------------------------------------------------------------
00881     //  Implementation of the XMLErrorReporter interface.
00882     // -----------------------------------------------------------------------
00883 
00886 
00911     virtual void error
00912     (
00913         const   unsigned int                errCode
00914         , const XMLCh* const                msgDomain
00915         , const XMLErrorReporter::ErrTypes  errType
00916         , const XMLCh* const                errorText
00917         , const XMLCh* const                systemId
00918         , const XMLCh* const                publicId
00919         , const unsigned int                lineNum
00920         , const unsigned int                colNum
00921     );
00922 
00931     virtual void resetErrors();
00933 
00934 
00935     // -----------------------------------------------------------------------
00936     //  Implementation of the XMLEntityHandler interface.
00937     // -----------------------------------------------------------------------
00938 
00941 
00954     virtual void endInputSource(const InputSource& inputSource);
00955 
00971     virtual bool expandSystemId
00972     (
00973         const   XMLCh* const    systemId
00974         ,       XMLBuffer&      toFill
00975     );
00976 
00985     virtual void resetEntities();
00986 
01002     virtual InputSource* resolveEntity
01003     (
01004         const   XMLCh* const    publicId
01005         , const XMLCh* const    systemId
01006     );
01007 
01020     virtual void startInputSource(const InputSource& inputSource);
01021 
01023 
01024 
01025 
01026     // -----------------------------------------------------------------------
01027     //  Implementation of the XMLDocumentHandler interface.
01028     // -----------------------------------------------------------------------
01029 
01032 
01045     virtual void docCharacters
01046     (
01047         const   XMLCh* const    chars
01048         , const unsigned int    length
01049         , const bool            cdataSection
01050     );
01051 
01060     virtual void docComment
01061     (
01062         const   XMLCh* const    comment
01063     );
01064 
01077     virtual void docPI
01078     (
01079         const   XMLCh* const    target
01080         , const XMLCh* const    data
01081     );
01082 
01087     virtual void endDocument();
01088 
01102     virtual void endElement
01103     (
01104         const   XMLElementDecl& elemDecl
01105         , const unsigned int    urlId
01106         , const bool            isRoot
01107     );
01108 
01117     virtual void endEntityReference
01118     (
01119         const   XMLEntityDecl&  entDecl
01120     );
01121 
01140     virtual void ignorableWhitespace
01141     (
01142         const   XMLCh* const    chars
01143         , const unsigned int    length
01144         , const bool            cdataSection
01145     );
01146 
01153     virtual void resetDocument();
01154 
01159     virtual void startDocument();
01160 
01188     virtual void startElement
01189     (
01190         const   XMLElementDecl&         elemDecl
01191         , const unsigned int            urlId
01192         , const XMLCh* const            elemPrefix
01193         , const RefVectorOf<XMLAttr>&   attrList
01194         , const unsigned int            attrCount
01195         , const bool                    isEmpty
01196         , const bool                    isRoot
01197     );
01198 
01208     virtual void startEntityReference
01209     (
01210         const   XMLEntityDecl&  entDecl
01211     );
01212 
01231     virtual void XMLDecl
01232     (
01233         const   XMLCh* const    versionStr
01234         , const XMLCh* const    encodingStr
01235         , const XMLCh* const    standaloneStr
01236         , const XMLCh* const    actualEncStr
01237     );
01239 
01240 
01243 
01257     void setExpandEntityReferences(const bool expand);
01258 
01270     bool getExpandEntityReferences() const;
01271 
01285     bool getDoValidation() const;
01286 
01303     void setDoValidation(const bool newState);
01304 
01308     virtual void attDef
01309     (
01310         const   DTDElementDecl&     elemDecl
01311         , const DTDAttDef&          attDef
01312         , const bool                ignoring
01313     );
01314 
01315     virtual void doctypeComment
01316     (
01317         const   XMLCh* const    comment
01318     );
01319 
01320     virtual void doctypeDecl
01321     (
01322         const   DTDElementDecl& elemDecl
01323         , const XMLCh* const    publicId
01324         , const XMLCh* const    systemId
01325         , const bool            hasIntSubset
01326     );
01327 
01328     virtual void doctypePI
01329     (
01330         const   XMLCh* const    target
01331         , const XMLCh* const    data
01332     );
01333 
01334     virtual void doctypeWhitespace
01335     (
01336         const   XMLCh* const    chars
01337         , const unsigned int    length
01338     );
01339 
01340     virtual void elementDecl
01341     (
01342         const   DTDElementDecl& decl
01343         , const bool            isIgnored
01344     );
01345 
01346     virtual void endAttList
01347     (
01348         const   DTDElementDecl& elemDecl
01349     );
01350 
01351     virtual void endIntSubset();
01352 
01353     virtual void endExtSubset();
01354 
01355     virtual void entityDecl
01356     (
01357         const   DTDEntityDecl&  entityDecl
01358         , const bool            isPEDecl
01359         , const bool            isIgnored
01360     );
01361 
01362     virtual void resetDocType();
01363 
01364     virtual void notationDecl
01365     (
01366         const   XMLNotationDecl&    notDecl
01367         , const bool                isIgnored
01368     );
01369 
01370     virtual void startAttList
01371     (
01372         const   DTDElementDecl& elemDecl
01373     );
01374 
01375     virtual void startIntSubset();
01376 
01377     virtual void startExtSubset();
01378 
01379     virtual void TextDecl
01380     (
01381         const   XMLCh* const    versionStr
01382         , const XMLCh* const    encodingStr
01383     );
01384 
01385 
01387 
01388 
01389 protected :
01390     // -----------------------------------------------------------------------
01391     //  Protected getter methods
01392     // -----------------------------------------------------------------------
01393 
01396 
01401     DOM_Node getCurrentNode();
01402 
01404 
01405 
01406     // -----------------------------------------------------------------------
01407     //  Protected setter methods
01408     // -----------------------------------------------------------------------
01409 
01412 
01420     void setCurrentNode(DOM_Node toSet);
01421 
01428     void setDocument(DOM_Document toSet);
01430 
01431 
01432 private :
01433     // -----------------------------------------------------------------------
01434     //  Private data members
01435     //
01436     //  fCurrentNode
01437     //  fCurrentParent
01438     //      Used to track the current node during nested element events. Since
01439     //      the tree must be built from a set of disjoint callbacks, we need
01440     //      these to keep up with where we currently are.
01441     //
01442     //  fDocument
01443     //      The root document object, filled with the document contents.
01444     //
01445     //  fEntityResolver
01446     //      The installed SAX entity resolver, if any. Null if none.
01447     //
01448     //  fErrorHandler
01449     //      The installed SAX error handler, if any. Null if none.
01450     //
01451     //  fCreateEntityReferenceNode
01452     //      Indicates whether entity reference nodes should be created.
01453     //
01454     //  fIncludeIgnorableWhitespace
01455     //      Indicates whether ignorable whiltespace should be added to
01456     //      the DOM tree for validating parsers.
01457     //
01458     //  fNodeStack
01459     //      Used to track previous parent nodes during nested element events.
01460     //
01461     //  fParseInProgress
01462     //      Used to prevent multiple entrance to the parser while its doing
01463     //      a parse.
01464     //
01465     //  fScanner
01466     //      The scanner used for this parser. This is created during the
01467     //      constructor.
01468     //
01469     //  fWithinElement
01470     //      A flag to indicate that the parser is within at least one level
01471     //      of element processing.
01472     //
01473     //  fDocumentType
01474     //      Used to store and update the documentType variable information
01475     //      in fDocument
01476     //
01477     //  fToCreateXMLDecTypeNode
01478     //      A flag to create a DOM_XMLDecl node in the ODM tree if it exists
01479     //      This is an extension to xerces implementation
01480     //
01481     // -----------------------------------------------------------------------
01482     DOM_Node                fCurrentParent;
01483     DOM_Node                fCurrentNode;
01484     DOM_Document            fDocument;
01485     EntityResolver*         fEntityResolver;
01486     ErrorHandler*           fErrorHandler;
01487     bool                    fCreateEntityReferenceNodes;
01488     bool                    fIncludeIgnorableWhitespace;
01489     ValueStackOf<DOM_Node>* fNodeStack;
01490     bool                    fParseInProgress;
01491     XMLScanner*             fScanner;
01492     bool                    fWithinElement;
01493     DocumentTypeImpl*       fDocumentType;
01494     bool                    fToCreateXMLDeclTypeNode;
01495 };
01496 
01497 
01498 
01499 // ---------------------------------------------------------------------------
01500 //  DOMParser: Handlers for the XMLEntityHandler interface
01501 // ---------------------------------------------------------------------------
01502 inline void DOMParser::endInputSource(const InputSource&)
01503 {
01504     // The DOM entity resolver doesn't handle this
01505 }
01506 
01507 inline bool DOMParser::expandSystemId(const XMLCh* const, XMLBuffer&)
01508 {
01509     // The DOM entity resolver doesn't handle this
01510     return false;
01511 }
01512 
01513 inline void DOMParser::resetEntities()
01514 {
01515     // Nothing to do on this one
01516 }
01517 
01518 inline void DOMParser::startInputSource(const InputSource&)
01519 {
01520     // The DOM entity resolver doesn't handle this
01521 }
01522 
01523 
01524 // ---------------------------------------------------------------------------
01525 //  DOMParser: Getter methods
01526 // ---------------------------------------------------------------------------
01527 inline DOM_Document DOMParser::getDocument()
01528 {
01529     return fDocument;
01530 }
01531 
01532 inline ErrorHandler* DOMParser::getErrorHandler()
01533 {
01534     return fErrorHandler;
01535 }
01536 
01537 inline const ErrorHandler* DOMParser::getErrorHandler() const
01538 {
01539     return fErrorHandler;
01540 }
01541 
01542 inline EntityResolver* DOMParser::getEntityResolver()
01543 {
01544     return fEntityResolver;
01545 }
01546 
01547 inline const EntityResolver* DOMParser::getEntityResolver() const
01548 {
01549     return fEntityResolver;
01550 }
01551 
01552 inline bool DOMParser::getExpandEntityReferences() const
01553 {
01554     return fCreateEntityReferenceNodes;
01555 }
01556 inline bool DOMParser::getCreateEntityReferenceNodes() const
01557 {
01558     return fCreateEntityReferenceNodes;
01559 }
01560 
01561 inline bool DOMParser::getIncludeIgnorableWhitespace() const
01562 {
01563     return fIncludeIgnorableWhitespace;
01564 }
01565 
01566 inline const XMLScanner& DOMParser::getScanner() const
01567 {
01568     return *fScanner;
01569 }
01570 
01571 inline bool DOMParser::getToCreateXMLDeclTypeNode() const
01572 {
01573     return fToCreateXMLDeclTypeNode;
01574 }
01575 
01576 
01577 // ---------------------------------------------------------------------------
01578 //  DOMParser: Setter methods
01579 // ---------------------------------------------------------------------------
01580 inline void DOMParser::setExpandEntityReferences(const bool expand)
01581 {
01582     fCreateEntityReferenceNodes = expand;
01583 }
01584 
01585 inline void DOMParser::setCreateEntityReferenceNodes(const bool create)
01586 {
01587     fCreateEntityReferenceNodes = create;
01588 }
01589 
01590 inline void DOMParser::setIncludeIgnorableWhitespace(const bool include)
01591 {
01592     fIncludeIgnorableWhitespace = include;
01593 }
01594 
01595 inline void DOMParser::setToCreateXMLDeclTypeNode(const bool create)
01596 {
01597     fToCreateXMLDeclTypeNode = create;
01598 }
01599 
01600 
01601 // ---------------------------------------------------------------------------
01602 //  DOMParser: Protected getter methods
01603 // ---------------------------------------------------------------------------
01604 inline DOM_Node DOMParser::getCurrentNode()
01605 {
01606     return fCurrentNode;
01607 }
01608 
01609 
01610 // ---------------------------------------------------------------------------
01611 //  DOMParser: Protected setter methods
01612 // ---------------------------------------------------------------------------
01613 inline void DOMParser::setCurrentNode(DOM_Node toSet)
01614 {
01615     fCurrentNode = toSet;
01616 }
01617 
01618 inline void DOMParser::setDocument(DOM_Document toSet)
01619 {
01620     fDocument = toSet;
01621 }
01622 
01623 #endif


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