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 
00035 const int RESIZE_BUFFER = 16;
00036 
00037 
00038 class XmlPullParser
00039 {
00040  public:
00041   //features
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   //constructor
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   // utility methods to make XML parsing easier ...
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   //  void setProperty(std::string property,  std::string value);
00118 
00119 
00120   //enum for event types
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   //returns the state name as  a std::string
00140   std::string state (int eventType);
00141   bool isProp (std::string n1, bool prop, std::string n2);
00142   bool adjustNsp ();                            //throws XmlPullParserException
00143   std::string *ensureCapacity (std::string * arr, int required);
00144   void exception (std::string desc);                 //throws XmlPullParserException
00145 
00149   void nextImpl ();                             //throws IOException, XmlPullParserException
00150   int parseLegacy (bool push);
00151 
00152   //throws IOException, XmlPullParserException
00153 
00155   void parseDoctype (bool push);
00156 
00157   /* precondition: &lt;/ consumed */
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   //vivek
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   // general
00191   std::string version;
00192   bool standalone;
00193 
00194   //   private bool reportNspAttr;
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   //    private bool eof;
00212   int line;
00213   int column;
00214 
00215   // txtbuffer
00216   char *txtBuf;
00217   int txtPos;
00218   int txtBufSize;
00219 
00220   // Event-related
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   // source
00231   std::istream & reader;
00232 
00236   int peek[2];
00237   int peekCount;
00238   bool wasCR;
00239   bool unresolved;
00240   bool token;
00241 };
00242 #endif                                            /*  */

Generated on Sun Oct 16 10:11:52 2005 for wsdlpull by  doxygen 1.3.9.1