/* expatParser.h A class that presents a nice C++ interface to the expat library (which is all plain C). Puts its results into an object passed in by the user (which is subclassed from docObjectIface). http://projects.zillabit.com/xml.html Copyright (c) 2000, Earl Levine All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: -Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -The name of Earl Levine may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _EXPATPARSER_H_ #define _EXPATPARSER_H_ #include "xmlparse/xmlparse.h" class docObjectIface; class expatParser { public: expatParser(docObjectIface *docObject, bool allowExpansionOfInternalEntities =true); ~expatParser(); // Call this at least once with the segments of your document in sequence. // Set the flag isFinal to true on the last call only. // Returns true upon success, false upon failure. // If there is a parsing error: // 1. an error description is returned in *pErrorString, caller must call delete[] on it. // This method will call delete[] on *pErrorString so make sure that's safe. // 2. if pErrorLineNumber is non-NULL the line number is returned in it bool parse(const char *documentSegment, int documentSegmentLength, bool isFinal, XML_LChar **pErrorString, int *pErrorLineNumber); // Expat callback handlers. They just pass the calls through to // the docObjectIface object. It would be nice to not make these public // but that won't work because they have to be callable from C functions. void StartElementHandler(const XML_Char *name, const XML_Char **atts); void EndElementHandler(const XML_Char *name); void CharacterDataHandler(const XML_Char *s, int len); void ProcessingInstructionHandler(const XML_Char *target, const XML_Char *data); void CommentHandler(const XML_Char *data); void StartCdataSectionHandler(); void EndCdataSectionHandler(); void DefaultHandler(const XML_Char *s, int len); void UnparsedEntityDeclHandler(const XML_Char *entityName, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId, const XML_Char *notationName); void NotationDeclHandler(const XML_Char *notationName, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId); void StartNamespaceDeclHandler(const XML_Char *prefix, const XML_Char *uri); void EndNamespaceDeclHandler(const XML_Char *prefix); // There are other handlers declared in xmlparse.h that could be added here... protected: XML_Parser m_parserInstance; docObjectIface *m_docObject; bool m_allowExpansionOfInternalEntities; }; #endif /* _EXPATPARSER_H_ */