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
00034 #ifndef WSDLPULL_EXPORT
00035 #if (defined _MSC_VER) && (defined _MT)
00036 #define WSDLPULL_EXPORT __declspec (dllimport)
00037 #else
00038 #define WSDLPULL_EXPORT
00039 #endif
00040 #endif
00041
00042
00044 const int RESIZE_BUFFER = 16;
00045
00046
00047
00048 #define FEATURE_PROCESS_NAMESPACES "http://xmlpull.org/v1/doc/features.html#process-namespaces"
00049 #define FEATURE_REPORT_NAMESPACE_ATTRIBUTES "http://xmlpull.org/v1/doc/features.html#report-namespace-prefixes"
00050 #define FEATURE_PROCESS_DOCDECL "http://xmlpull.org/v1/doc/features.html#process-docdecl"
00051 #define FEATURE_VALIDATION "http://xmlpull.org/v1/doc/features.html#validation"
00052 #define NO_NAMESPACE ""
00053
00054 class WSDLPULL_EXPORT XmlPullParser
00055 {
00056 public:
00057
00058 XmlPullParser (std::istream & is);
00059
00060 XmlPullParser (void);
00061 ~XmlPullParser (void);
00062 bool getFeature (std::string feature);
00063 std::string getInputEncoding ();
00064 void defineEntityReplacementText (std::string entity, std::string value);
00065 int getNamespaceCount (int depth);
00066 std::string getNamespacePrefix (int pos);
00067 std::string getNamespaceUri (int pos);
00068 std::string getNamespace (std::string prefix);
00069
00070 int getDepth ();
00071 std::string getPositionDescription ();
00072 int getLineNumber ()
00073 {
00074 return line;
00075 }
00076 int getColumnNumber ()
00077 {
00078 return column;
00079 }
00080 bool isWhitespace ();
00081 std::string getText ();
00082 const char *getTextCharacters (int *poslen);
00083 std::string getNamespace ()
00084 {
00085 return Ns;
00086 }
00087 std::string getName ()
00088 {
00089 return name;
00090 }
00091 std::string getPrefix ()
00092 {
00093 return prefix;
00094 }
00095 bool isEmptyElementTag ();
00096 int getAttributeCount ()
00097 {
00098 return attributeCount;
00099 }
00100 std::string getAttributeType (int index)
00101 {
00102 return "CDATA";
00103 }
00104 bool isAttributeDefault (int index)
00105 {
00106 return false;
00107 }
00108 std::string getAttributeNamespace (int index);
00109 std::string getAttributeName (int index);
00110 std::string getAttributePrefix (int index);
00111 std::string getAttributeValue (int index);
00112 std::string getAttributeValue (std::string ns, std::string name);
00113 int getEventType ()
00114 {
00115 return type;
00116 }
00117
00118 int next ();
00119 int nextToken ();
00120 int nextTag ();
00121
00122
00123
00124 void require (int type, std::string ns, std::string name);
00125 std::string nextText ();
00126 void setFeature (std::string feature, bool value);
00127 void skipSubTree() ;
00128
00129
00130
00131
00132 enum
00133 {
00134 START_DOCUMENT ,
00135 END_DOCUMENT,
00136 START_TAG,
00137 END_TAG,
00138 TEXT,
00139 CDSECT,
00140 ENTITY_REF,
00141 IGNORABLE_WHITESPACE,
00142 PROCESSING_INSTRUCTION,
00143 COMMENT,
00144 DOCDECL
00145 };
00146 private:
00147 void commonInit (void);
00148 void initBuf (void);
00149
00150
00151 std::string state (int eventType);
00152 bool isProp (std::string n1, bool prop, std::string n2);
00153 bool adjustNsp ();
00154 std::string *ensureCapacity (std::string * arr, int required);
00155 void exception (std::string desc);
00156
00160 void nextImpl ();
00161 int parseLegacy (bool push);
00162
00163
00164
00166 void parseDoctype (bool push);
00167
00168
00169 void parseEndTag ();
00170 int peekType ();
00171 std::string get (int pos);
00172 void push (int c);
00173
00175 void parseStartTag (bool xmldecl);
00176
00180
00181 void pushEntity ();
00182
00188 void pushText (int delimiter, bool resolveEntities);
00189 void read (char c);
00190 int read ();
00191
00193 int peekbuf (int pos);
00194 std::string readName ();
00195 void skip ();
00196 std::string unexpected_eof;
00197 std::string illegal_type;
00198 int LEGACY;
00199 int XML_DECL;
00200
00201
00202 std::string version;
00203 bool standalone;
00204
00205
00206 bool processNsp;
00207 bool relaxed;
00208 std::map < std::string, std::string > entityMap;
00209 int depth;
00210 std::vector < std::string > nspStack;
00211 std::vector < std::string > elementStack;
00212 int *nspCounts;
00213 int nspSize;
00214
00215
00216 std::string encoding;
00217 char *srcBuf;
00218 int srcPos;
00219 int srcCount;
00220 int srcBuflength;
00221
00222
00223 int line;
00224 int column;
00225
00226
00227 char *txtBuf;
00228 int txtPos;
00229 int txtBufSize;
00230
00231
00232 int type;
00233 std::string text;
00234 bool isWspace;
00235 std::string Ns;
00236 std::string prefix;
00237 std::string name;
00238 bool degenerated;
00239 int attributeCount;
00240 std::vector < std::string > attributes;
00241
00242 std::istream & reader;
00243
00247 int peek[2];
00248 int peekCount;
00249 bool wasCR;
00250 bool unresolved;
00251 bool token;
00252 };
00253 #endif