00001
00002
00003 #ifndef MIX_SAXPARSER_H_
00004 #define MIX_SAXPARSER_H_
00005
00006 #include <map>
00007 #include <stack>
00008
00009 #include "classes.h"
00010 #include "DefaultXMLTraits.h"
00011 #include "misc.h"
00012 #include "Tokenizer.h"
00013 #include "SAX_EventHandler.h"
00014 #include "XMLString.h"
00015 #include "AttrMap.h"
00016
00017 namespace MiX{
00022 template <class Char,class Traits,class XMLTraits>
00023 class SAX_Parser{
00024 public:
00025 MiX_Template_Typedef(Char,Traits,XMLTraits);
00026 typedef SAX_Parser<Char,Traits,XMLTraits> this_type;
00027 typedef NodeContainer<Char,Traits,XMLTraits> nodecontainer_type;
00028 private:
00029 enum State{
00030 STATE_Text,
00031 STATE_Tag,
00032 STATE_Reference,
00033 STATE_Comment,
00034 STATE_Complete,
00035 STATE_Declaration,
00036 STATE_XMLDeclaration,
00037 STATE_Escape,
00038 STATE_Exception
00039 };
00040
00041 State state_;
00042 Tokenizer<Char,Traits,XMLTraits> tokenizer_;
00043 SAX_EventHandler<Char,Traits,XMLTraits>* handler_;
00044 MiX_STD::stack<XMLString<Char,Traits,XMLTraits> > validator_;
00045
00046 bool ignore_space_;
00047
00048 void skipSpaceTokens();
00049
00050 State parseText();
00051 State parseTag();
00052 State parseComment();
00053 State parseDeclaration();
00054 State parseXMLDeclaration();
00055
00056 AttrMap<Char,Traits,XMLTraits> parseAttributes();
00057 XMLString<Char,Traits,XMLTraits> parseReference();
00058
00059 void trimRight(XMLString<Char,Traits,XMLTraits>& str);
00060 public:
00062 SAX_Parser(){ handler_ = NULL; };
00069 void setEventHandler(SAX_EventHandler<Char,Traits,XMLTraits>* handler){
00070 handler_ = handler;
00071 };
00078 void setIgnoreSpace(bool flag) { ignore_space_ = flag; };
00085 bool parse(const Char* szText);
00086 };
00087 }
00088
00089 #ifndef MIX_SAXPARSER_CPP_
00090 #include "SAX_Parser.cpp"
00091 #endif
00092
00093 #endif