Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

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           
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 //features
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   //constructor
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   //parsing methods
00118   int next ();
00119   int nextToken ();
00120   int nextTag ();
00121 
00122   //----------------------------------------------------------------------
00123   // utility methods to make XML parsing easier ...
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   //  void setProperty(std::string property,  std::string value);
00129 
00130 
00131   //enum for event types
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   //returns the state name as  a std::string
00151   std::string state (int eventType);
00152   bool isProp (std::string n1, bool prop, std::string n2);
00153   bool adjustNsp ();                            //throws XmlPullParserException
00154   std::string *ensureCapacity (std::string * arr, int required);
00155   void exception (std::string desc);                 //throws XmlPullParserException
00156 
00160   void nextImpl ();                             //throws IOException, XmlPullParserException
00161   int parseLegacy (bool push);
00162 
00163   //throws IOException, XmlPullParserException
00164 
00166   void parseDoctype (bool push);
00167 
00168   /* precondition: &lt;/ consumed */
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   //vivek
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   // general
00202   std::string version;
00203   bool standalone;
00204 
00205   //   private bool reportNspAttr;
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   //    private bool eof;
00223   int line;
00224   int column;
00225 
00226   // txtbuffer
00227   char *txtBuf;
00228   int txtPos;
00229   int txtBufSize;
00230 
00231   // Event-related
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   // source
00242   std::istream & reader;
00243 
00247   int peek[2];
00248   int peekCount;
00249   bool wasCR;
00250   bool unresolved;
00251   bool token;
00252 };
00253 #endif                                            /*  */

Generated on Mon Feb 6 23:02:42 2006 for wsdlpull by  doxygen 1.3.9.1