00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _XMLPULLPARSERH
00023 #define _XMLPULLPARSERH
00024
00025 #include <map>
00026 #include <iostream>
00027 #include <sstream>
00028 #include <string>
00029 #include <vector>
00030 #ifdef HAVE_CONFIG_H //
00031 #include <config.h>
00032 #endif
00033
00035 const int RESIZE_BUFFER = 16;
00036
00037
00038 class XmlPullParser
00039 {
00040 public:
00041
00042 const static std::string FEATURE_PROCESS_NAMESPACES;
00043 const static std::string FEATURE_REPORT_NAMESPACE_ATTRIBUTES;
00044 const static std::string FEATURE_PROCESS_DOCDECL;
00045 const static std::string FEATURE_VALIDATION ;
00046 const static std::string NO_NAMESPACE;
00047
00048 XmlPullParser (std::istream & is);
00049
00050 XmlPullParser (void);
00051 ~XmlPullParser (void);
00052 bool getFeature (std::string feature);
00053 std::string getInputEncoding ();
00054 void defineEntityReplacementText (std::string entity, std::string value);
00055 int getNamespaceCount (int depth);
00056 std::string getNamespacePrefix (int pos);
00057 std::string getNamespaceUri (int pos);
00058 std::string getNamespace (std::string prefix);
00059
00060 int getDepth ();
00061 std::string getPositionDescription ();
00062 int getLineNumber ()
00063 {
00064 return line;
00065 }
00066 int getColumnNumber ()
00067 {
00068 return column;
00069 }
00070 bool isWhitespace ();
00071 std::string getText ();
00072 const char *getTextCharacters (int *poslen);
00073 std::string getNamespace ()
00074 {
00075 return Ns;
00076 }
00077 std::string getName ()
00078 {
00079 return name;
00080 }
00081 std::string getPrefix ()
00082 {
00083 return prefix;
00084 }
00085 bool isEmptyElementTag ();
00086 int getAttributeCount ()
00087 {
00088 return attributeCount;
00089 }
00090 std::string getAttributeType (int index)
00091 {
00092 return "CDATA";
00093 }
00094 bool isAttributeDefault (int index)
00095 {
00096 return false;
00097 }
00098 std::string getAttributeNamespace (int index);
00099 std::string getAttributeName (int index);
00100 std::string getAttributePrefix (int index);
00101 std::string getAttributeValue (int index);
00102 std::string getAttributeValue (std::string ns, std::string name);
00103 int getEventType ()
00104 {
00105 return type;
00106 }
00107 int next ();
00108 int nextToken ();
00109
00110
00111
00112 int nextTag ();
00113 void require (int type, std::string ns, std::string name);
00114 std::string nextText ();
00115 void setFeature (std::string feature, bool value);
00116 void skipSubTree() ;
00117
00118
00119
00120
00121 enum
00122 {
00123 START_DOCUMENT ,
00124 END_DOCUMENT,
00125 START_TAG,
00126 END_TAG,
00127 TEXT,
00128 CDSECT,
00129 ENTITY_REF,
00130 IGNORABLE_WHITESPACE,
00131 PROCESSING_INSTRUCTION,
00132 COMMENT,
00133 DOCDECL
00134 };
00135 private:
00136 void commonInit (void);
00137 void initBuf (void);
00138
00139
00140 std::string state (int eventType);
00141 bool isProp (std::string n1, bool prop, std::string n2);
00142 bool adjustNsp ();
00143 std::string *ensureCapacity (std::string * arr, int required);
00144 void exception (std::string desc);
00145
00149 void nextImpl ();
00150 int parseLegacy (bool push);
00151
00152
00153
00155 void parseDoctype (bool push);
00156
00157
00158 void parseEndTag ();
00159 int peekType ();
00160 std::string get (int pos);
00161 void push (int c);
00162
00164 void parseStartTag (bool xmldecl);
00165
00169
00170 void pushEntity ();
00171
00177 void pushText (int delimiter, bool resolveEntities);
00178 void read (char c);
00179 int read ();
00180
00182 int peekbuf (int pos);
00183 std::string readName ();
00184 void skip ();
00185 std::string unexpected_eof;
00186 std::string illegal_type;
00187 int LEGACY;
00188 int XML_DECL;
00189
00190
00191 std::string version;
00192 bool standalone;
00193
00194
00195 bool processNsp;
00196 bool relaxed;
00197 std::map < std::string, std::string > entityMap;
00198 int depth;
00199 std::vector < std::string > nspStack;
00200 std::vector < std::string > elementStack;
00201 int *nspCounts;
00202 int nspSize;
00203
00204
00205 std::string encoding;
00206 char *srcBuf;
00207 int srcPos;
00208 int srcCount;
00209 int srcBuflength;
00210
00211
00212 int line;
00213 int column;
00214
00215
00216 char *txtBuf;
00217 int txtPos;
00218 int txtBufSize;
00219
00220
00221 int type;
00222 std::string text;
00223 bool isWspace;
00224 std::string Ns;
00225 std::string prefix;
00226 std::string name;
00227 bool degenerated;
00228 int attributeCount;
00229 std::vector < std::string > attributes;
00230
00231 std::istream & reader;
00232
00236 int peek[2];
00237 int peekCount;
00238 bool wasCR;
00239 bool unresolved;
00240 bool token;
00241 };
00242 #endif