00001 // @(#)root/xmlparser:$Id: TXMLParser.h 29654 2009-07-31 14:34:14Z rdm $ 00002 // Author: Jose Lo 12/4/2005 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 #ifndef ROOT_TXMLParser 00013 #define ROOT_TXMLParser 00014 00015 ////////////////////////////////////////////////////////////////////////// 00016 // // 00017 // TXMLParser // 00018 // // 00019 // TXMLParser is an abstract class which interfaces with Libxml2. // 00020 // Libxml2 is the XML C parser and toolkit developed for the Gnome // 00021 // project. // 00022 // // 00023 // The libxml library provides two interfaces to the parser, a DOM // 00024 // style tree interface and a SAX style event based interface. // 00025 // // 00026 // TXMLParser is parent class of TSAXParser and TDOMParser, which are // 00027 // a SAX interface and DOM interface of libxml. // 00028 // // 00029 ////////////////////////////////////////////////////////////////////////// 00030 00031 #ifndef ROOT_TQObject 00032 #include "TQObject.h" 00033 #endif 00034 00035 #ifndef ROOT_TObject 00036 #include "TObject.h" 00037 #endif 00038 00039 #ifndef ROOT_TString 00040 #include "TString.h" 00041 #endif 00042 00043 struct _xmlParserCtxt; 00044 00045 00046 class TXMLParser : public TObject, public TQObject { 00047 00048 private: 00049 TXMLParser(const TXMLParser&); // Not implemented 00050 TXMLParser& operator=(const TXMLParser&); // Not implemented 00051 00052 protected: 00053 _xmlParserCtxt *fContext; // parse the xml file 00054 Bool_t fValidate; // to validate the parse context 00055 Bool_t fReplaceEntities; // replace entities 00056 Bool_t fStopError; // stop when parse error occurs 00057 TString fValidateError; // parse error 00058 TString fValidateWarning; // parse warning 00059 Int_t fParseCode; // to keep track of the errorcodes 00060 00061 virtual void InitializeContext(); 00062 virtual void ReleaseUnderlying(); 00063 virtual void OnValidateError(const TString& message); 00064 virtual void OnValidateWarning(const TString& message); 00065 virtual void SetParseCode(Int_t code); 00066 00067 public: 00068 TXMLParser(); 00069 virtual ~TXMLParser(); 00070 00071 void SetValidate(Bool_t val = kTRUE); 00072 Bool_t GetValidate() const { return fValidate; } 00073 00074 void SetReplaceEntities(Bool_t val = kTRUE); 00075 Bool_t GetReplaceEntities() const { return fReplaceEntities; } 00076 00077 virtual Int_t ParseFile(const char *filename) = 0; 00078 virtual Int_t ParseBuffer(const char *contents, Int_t len) = 0; 00079 virtual void StopParser(); 00080 00081 Int_t GetParseCode() const { return fParseCode; } 00082 00083 const char *GetParseCodeMessage(Int_t parseCode) const; 00084 00085 void SetStopOnError(Bool_t stop = kTRUE); 00086 Bool_t GetStopOnError() const { return fStopError; } 00087 00088 const char *GetValidateError() const { return fValidateError; } 00089 const char *GetValidateWarning() const { return fValidateWarning; } 00090 00091 ClassDef(TXMLParser,0); // XML SAX parser 00092 }; 00093 00094 #endif