00001
00002
00003
00004
00005
00006
00007 #ifndef dsExpat_h
00008 #define dsExpat_h
00009
00010 #ifdef HAVE_CONFIG_H
00011 # include <config.h>
00012 #endif
00013
00014 #include <iostream>
00015 #include <stack>
00016
00017 #include <dsSmartException.h>
00018 #include <dsHashTable.h>
00019 #include <dsutil.h>
00020
00021 using namespace std;
00022
00023 class dsExpatException : public dsSmartException
00024 {
00025 int _lineno;
00026 int _colno;
00027
00028 public:
00029 dsExpatException(int lineno, int colno, const char *format, ... )
00030 {
00031 _lineno = lineno;
00032 _colno = colno;
00033 va_list ap;
00034 va_start(ap, format);
00035 fire( "dsExpat", (char *) format, ap);
00036 va_end(ap);
00037 }
00038
00039
00040 std::ostream& print(std::ostream& os)
00041 {
00042 os << tag() << ":"<< _lineno << ":" << _colno << ": " << msg() << std::endl;
00043 return os;
00044 }
00045 };
00046
00047
00048 typedef stack <char *> tagStack;
00049
00050 class dsExpat
00051 {
00052 long _byte_index;
00053 int _line_num;
00054 int _col_num;
00055
00056 char * _encoding;
00057
00058 tagStack _st;
00059
00060 void readEntity(istream& is);
00061
00062 protected:
00063 dsExpat(const char *encoding = 0);
00064 virtual ~dsExpat();
00065
00066
00067 virtual void StartElementHandler(const char *name, dsHashTable* atts);
00068 virtual void EndElementHandler(const char *name);
00069 virtual void CharacterDataHandler(const char *s, int len);
00070 virtual void ProcessingInstructionHandler(const char *tagret, const char *data);
00071 virtual void CommentHandler(const char *data);
00072
00073 public:
00074 void Parse(std::istream& is);
00075 void Parse(const char *s, int len);
00076
00077 long GetCurrentByteIndex();
00078 int GetCurrentLineNumber();
00079 int GetCurrentColumnNumber();
00080
00081 const tagStack& GetElementStack();
00082 };
00083
00084
00085 inline long dsExpat::GetCurrentByteIndex()
00086 {
00087 return _byte_index;
00088 }
00089
00090 inline int dsExpat::GetCurrentLineNumber()
00091 {
00092 return _line_num;
00093 }
00094
00095 inline int dsExpat::GetCurrentColumnNumber()
00096 {
00097 return _col_num;
00098 }
00099
00100 inline const tagStack& dsExpat::GetElementStack()
00101 {
00102 return _st;
00103 }
00104
00105 class dsExpatDebug : public dsExpat
00106 {
00107
00108 public:
00109 dsExpatDebug(const char *encoding = 0);
00110
00111 protected:
00112
00113
00114 virtual void StartElementHandler(const char *name, dsHashTable *atts);
00115 virtual void EndElementHandler(const char *name);
00116 virtual void CharacterDataHandler(const char *s, int len);
00117 virtual void ProcessingInstructionHandler(const char *tagret, const char *data);
00118 virtual void CommentHandler(const char *data);
00119
00120 };
00121
00122
00123 #endif