XmlPullParser.h

Go to the documentation of this file.
00001 /* Copyright (c) 2005,2007 Vivek Krishna
00002  *  Based on kxml2 by Stefan Haustein, Oberhausen, Rhld., Germany
00003  * Permission is hereby granted, free of charge, to any person obtaining a copy
00004  * of this software and associated documentation files (the "Software"), to deal
00005  * in the Software without restriction, including without limitation the rights
00006  * to use, copy, modify, merge, publish, distribute, sublicense, and/or
00007  * sell copies of the Software, and to permit persons to whom the Software is
00008  * furnished to do so, subject to the following conditions:
00009  *
00010  * The  above copyright notice and this permission notice shall be included in
00011  * all copies or substantial portions of the Software.
00012  *
00013  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00014  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00015  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00016  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00017  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00018  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
00019  * IN THE SOFTWARE. */
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 #include "wsdlpull_export.h"
00034 
00036 const int RESIZE_BUFFER = 16;
00037 
00038 
00039 //features
00040 #define FEATURE_PROCESS_NAMESPACES "http://xmlpull.org/v1/doc/features.html#process-namespaces"
00041 #define FEATURE_REPORT_NAMESPACE_ATTRIBUTES "http://xmlpull.org/v1/doc/features.html#report-namespace-prefixes"
00042 #define FEATURE_PROCESS_DOCDECL "http://xmlpull.org/v1/doc/features.html#process-docdecl"
00043 #define FEATURE_VALIDATION "http://xmlpull.org/v1/doc/features.html#validation"
00044 #define NO_NAMESPACE ""
00045 
00046 class WSDLPULL_EXPORT XmlPullParser
00047 {
00048  public:
00049  
00050   XmlPullParser (std::istream & is);
00051   //constructor
00052   XmlPullParser (void);
00053   ~XmlPullParser (void);
00054   bool getFeature (std::string feature);
00055   std::string getInputEncoding ();
00056   void defineEntityReplacementText (std::string entity, std::string value);
00057   int getNamespaceCount (int depth);
00058   std::string getNamespacePrefix (int pos);
00059   std::string getNamespaceUri (int pos);
00060   std::string getNamespace (std::string prefix);
00061   
00062   int getDepth ();
00063   std::string getPositionDescription ();
00064   int getLineNumber ()
00065     {
00066       return line;
00067     }
00068   int getColumnNumber ()
00069     {
00070       return column;
00071     }
00072   bool isWhitespace ();
00073   std::string getText ();
00074   const char *getTextCharacters (int *poslen);
00075   std::string getNamespace ()
00076     {
00077       return Ns;
00078     }
00079   std::string getName ()
00080     {
00081       return name;
00082     }
00083   std::string getPrefix ()
00084     {
00085       return prefix;
00086     }
00087   bool isEmptyElementTag ();
00088   int getAttributeCount ()
00089     {
00090       return attributeCount;
00091     }
00092   std::string getAttributeType (int /* index */)
00093     {
00094       return "CDATA";
00095     }
00096   bool isAttributeDefault (int /* index */)
00097     {
00098       return false;
00099     }
00100   std::string getAttributeNamespace (int index);
00101   std::string getAttributeName (int index);
00102   std::string getAttributePrefix (int index);
00103   std::string getAttributeValue (int index);
00104   std::string getAttributeValue (std::string ns, std::string name);
00105   int getEventType ()
00106     {
00107       return type;
00108     }
00109   //parsing methods
00110   int next ();
00111   int nextToken ();
00112   int nextTag ();
00113   void prevTag();
00114 
00115   //----------------------------------------------------------------------
00116   // utility methods to make XML parsing easier ...
00117   void require (int type, std::string ns, std::string name);
00118   std::string nextText ();
00119   void setFeature (std::string feature, bool value);
00120   void skipSubTree() ;
00121   //  void setProperty(std::string property,  std::string value);
00122 
00123 
00124   //enum for event types
00125   enum
00126     {
00127       START_DOCUMENT ,
00128       END_DOCUMENT,
00129       START_TAG,
00130       END_TAG,
00131       TEXT,
00132       CDSECT,
00133       ENTITY_REF,
00134       IGNORABLE_WHITESPACE,
00135       PROCESSING_INSTRUCTION,
00136       COMMENT,
00137       DOCDECL
00138     };
00139  private:
00140   void commonInit (void);
00141   void initBuf (void);
00142 
00143   //returns the state name as  a std::string
00144   std::string state (int eventType);
00145   bool isProp (std::string n1, bool prop, std::string n2);
00146   bool adjustNsp ();                            //throws XmlPullParserException
00147   std::string *ensureCapacity (std::string * arr, int required);
00148   void exception (std::string desc);                 //throws XmlPullParserException
00149 
00153   void nextImpl ();                             //throws IOException, XmlPullParserException
00154   int parseLegacy (bool push);
00155 
00156   //throws IOException, XmlPullParserException
00157 
00159   void parseDoctype (bool push);
00160 
00161   /* precondition: &lt;/ consumed */
00162   void parseEndTag ();
00163   int peekType ();
00164   std::string get (int pos);
00165   void push (int c);
00166 
00168   void parseStartTag (bool xmldecl);
00169 
00173   //vivek
00174   void pushEntity ();
00175 
00181   void pushText (int delimiter, bool resolveEntities);
00182   void read (char c);
00183   int read ();
00184 
00186   int peekbuf (int pos);
00187   std::string readName ();
00188   void skip ();
00189   std::string unexpected_eof;
00190   std::string illegal_type;
00191   int LEGACY;
00192   int XML_DECL;
00193 
00194   // general
00195   std::string version;
00196   bool standalone;
00197 
00198   //   private bool reportNspAttr;
00199   bool processNsp;
00200   bool relaxed;
00201   std::map < std::string, std::string > entityMap;
00202   int depth;
00203   std::vector < std::string > nspStack;
00204   std::vector < std::string > elementStack;
00205   int *nspCounts;
00206   int nspSize;
00207 
00208 
00209   std::string encoding;
00210   char *srcBuf;
00211   int srcPos;
00212   int srcCount;
00213   int srcBuflength;
00214 
00215   //    private bool eof;
00216   int line;
00217   int column;
00218 
00219   // txtbuffer
00220   char *txtBuf;
00221   int txtPos;
00222   int txtBufSize;
00223 
00224   // Event-related
00225   int type;
00226   std::string text;
00227   bool isWspace,skipNextTag;
00228   std::string Ns;
00229   std::string prefix;
00230   std::string name;
00231   bool degenerated;
00232   int attributeCount;
00233   std::vector < std::string > attributes;
00234   // source
00235   std::istream & reader;
00236 
00240   int peek[2];
00241   int peekCount;
00242   bool wasCR;
00243   bool unresolved;
00244   bool token;
00245 };
00246 #endif                                            /*  */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by  doxygen 1.6.2