wsdlpull 1.23
XmlPullParser.h
Go to the documentation of this file.
1/* Copyright (c) 2005,2007 Vivek Krishna
2 * Based on kxml2 by Stefan Haustein, Oberhausen, Rhld., Germany
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 * IN THE SOFTWARE. */
20
21
22#ifndef _XMLPULLPARSERH
23#define _XMLPULLPARSERH
24
25#include <map>
26#include <iostream>
27#include <sstream>
28#include <string>
29#include <vector>
30#ifdef HAVE_CONFIG_H //
31#include <config.h>
32#endif
33#include "wsdlpull_export.h"
34
36const int RESIZE_BUFFER = 16;
37
38
39//features
40#define FEATURE_PROCESS_NAMESPACES "http://xmlpull.org/v1/doc/features.html#process-namespaces"
41#define FEATURE_REPORT_NAMESPACE_ATTRIBUTES "http://xmlpull.org/v1/doc/features.html#report-namespace-prefixes"
42#define FEATURE_PROCESS_DOCDECL "http://xmlpull.org/v1/doc/features.html#process-docdecl"
43#define FEATURE_VALIDATION "http://xmlpull.org/v1/doc/features.html#validation"
44#define NO_NAMESPACE ""
45
47{
48 public:
49
50 XmlPullParser (std::istream & is);
51 //constructor
52 XmlPullParser (void);
53 ~XmlPullParser (void);
54 bool getFeature (std::string feature);
55 std::string getInputEncoding ();
56 void defineEntityReplacementText (std::string entity, std::string value);
57 int getNamespaceCount (int depth);
58 std::string getNamespacePrefix (int pos);
59 std::string getNamespaceUri (int pos);
60 std::string getNamespace (std::string prefix);
61
62 int getDepth ();
63 std::string getPositionDescription ();
65 {
66 return line;
67 }
69 {
70 return column;
71 }
72 bool isWhitespace ();
73 std::string getText ();
74 const char *getTextCharacters (int *poslen);
75 std::string getNamespace ()
76 {
77 return Ns;
78 }
79 std::string getName ()
80 {
81 return name;
82 }
83 std::string getPrefix ()
84 {
85 return prefix;
86 }
87 bool isEmptyElementTag ();
89 {
90 return attributeCount;
91 }
92 std::string getAttributeType (int /* index */)
93 {
94 return "CDATA";
95 }
96 bool isAttributeDefault (int /* index */)
97 {
98 return false;
99 }
100 std::string getAttributeNamespace (int index);
101 std::string getAttributeName (int index);
102 std::string getAttributePrefix (int index);
103 std::string getAttributeValue (int index);
104 std::string getAttributeValue (std::string ns, std::string name);
106 {
107 return type;
108 }
109 //parsing methods
110 int next ();
111 int nextToken ();
112 int nextTag ();
113 void prevTag();
114
115 //----------------------------------------------------------------------
116 // utility methods to make XML parsing easier ...
117 void require (int type, std::string ns, std::string name);
118 std::string nextText ();
119 void setFeature (std::string feature, bool value);
120 void skipSubTree() ;
121 // void setProperty(std::string property, std::string value);
122
123
124 //enum for event types
125 enum
126 {
137 DOCDECL
138 };
139 private:
140 void commonInit (void);
141 void initBuf (void);
142
143 //returns the state name as a std::string
144 std::string state (int eventType);
145 bool isProp (std::string n1, bool prop, std::string n2);
146 bool adjustNsp (); //throws XmlPullParserException
147 std::string *ensureCapacity (std::string * arr, int required);
148 void exception (std::string desc); //throws XmlPullParserException
149
153 void nextImpl (); //throws IOException, XmlPullParserException
154 int parseLegacy (bool push);
155
156 //throws IOException, XmlPullParserException
157
159 void parseDoctype (bool push);
160
161 /* precondition: &lt;/ consumed */
162 void parseEndTag ();
163 int peekType ();
164 std::string get (int pos);
165 void push (int c);
166
168 void parseStartTag (bool xmldecl);
169
173 //vivek
174 void pushEntity ();
175
181 void pushText (int delimiter, bool resolveEntities);
182 void read (char c);
183 int read ();
184
186 int peekbuf (int pos);
187 std::string readName ();
188 void skip ();
189 std::string unexpected_eof;
190 std::string illegal_type;
191 int LEGACY;
192 int XML_DECL;
193
194 // general
195 std::string version;
196 bool standalone;
197
198 // private bool reportNspAttr;
199 bool processNsp;
200 bool relaxed;
201 std::map < std::string, std::string > entityMap;
202 int depth;
203 std::vector < std::string > nspStack;
204 std::vector < std::string > elementStack;
205 int *nspCounts;
206 int nspSize;
207
208
209 std::string encoding;
210 char *srcBuf;
211 int srcPos;
212 int srcCount;
213 int srcBuflength;
214
215 // private bool eof;
216 int line;
217 int column;
218
219 // txtbuffer
220 char *txtBuf;
221 int txtPos;
222 int txtBufSize;
223
224 // Event-related
225 int type;
226 std::string text;
227 bool isWspace,skipNextTag;
228 std::string Ns;
229 std::string prefix;
230 std::string name;
231 bool degenerated;
232 int attributeCount;
233 std::vector < std::string > attributes;
234 // source
235 std::istream & reader;
236
240 int peek[2];
241 int peekCount;
242 bool wasCR;
243 bool unresolved;
244 bool token;
245};
246#endif /* */
const int RESIZE_BUFFER
Definition: XmlPullParser.h:36
std::string getNamespace()
Definition: XmlPullParser.h:75
std::string getAttributeType(int)
Definition: XmlPullParser.h:92
bool isAttributeDefault(int)
Definition: XmlPullParser.h:96
int getColumnNumber()
Definition: XmlPullParser.h:68
int getLineNumber()
Definition: XmlPullParser.h:64
std::string getName()
Definition: XmlPullParser.h:79
std::string getPrefix()
Definition: XmlPullParser.h:83
int getAttributeCount()
Definition: XmlPullParser.h:88
#define WSDLPULL_EXPORT