1 /*
2 * Summary: the XMLReader implementation
3 * Description: API of the XML streaming API based on C# interfaces.
4 *
5 * Copy: See Copyright for the status of this software.
6 *
7 * Author: Daniel Veillard
8 */
9
10 #ifndef __XML_XMLREADER_H__
11 #define __XML_XMLREADER_H__
12
13 #include <libxml/xmlversion.h>
14 #include <libxml/tree.h>
15 #include <libxml/xmlerror.h>
16 #include <libxml/xmlIO.h>
17 #ifdef LIBXML_SCHEMAS_ENABLED
18 #include <libxml/relaxng.h>
19 #include <libxml/xmlschemas.h>
20 #endif
21 /* for compatibility */
22 #include <libxml/parser.h>
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 /**
29 * xmlParserSeverities:
30 *
31 * How severe an error callback is when the per-reader error callback API
32 * is used.
33 */
34 typedef enum {
35 XML_PARSER_SEVERITY_VALIDITY_WARNING = 1,
36 XML_PARSER_SEVERITY_VALIDITY_ERROR = 2,
37 XML_PARSER_SEVERITY_WARNING = 3,
38 XML_PARSER_SEVERITY_ERROR = 4
39 } xmlParserSeverities;
40
41 #ifdef LIBXML_READER_ENABLED
42
43 /**
44 * xmlTextReaderMode:
45 *
46 * Internal state values for the reader.
47 */
48 typedef enum {
49 XML_TEXTREADER_MODE_INITIAL = 0,
50 XML_TEXTREADER_MODE_INTERACTIVE = 1,
51 XML_TEXTREADER_MODE_ERROR = 2,
52 XML_TEXTREADER_MODE_EOF =3,
53 XML_TEXTREADER_MODE_CLOSED = 4,
54 XML_TEXTREADER_MODE_READING = 5
55 } xmlTextReaderMode;
56
57 /**
58 * xmlParserProperties:
59 *
60 * Some common options to use with xmlTextReaderSetParserProp, but it
61 * is better to use xmlParserOption and the xmlReaderNewxxx and
62 * xmlReaderForxxx APIs now.
63 */
64 typedef enum {
65 XML_PARSER_LOADDTD = 1,
66 XML_PARSER_DEFAULTATTRS = 2,
67 XML_PARSER_VALIDATE = 3,
68 XML_PARSER_SUBST_ENTITIES = 4
69 } xmlParserProperties;
70
71 /**
72 * xmlReaderTypes:
73 *
74 * Predefined constants for the different types of nodes.
75 */
76 typedef enum {
77 XML_READER_TYPE_NONE = 0,
78 XML_READER_TYPE_ELEMENT = 1,
79 XML_READER_TYPE_ATTRIBUTE = 2,
80 XML_READER_TYPE_TEXT = 3,
81 XML_READER_TYPE_CDATA = 4,
82 XML_READER_TYPE_ENTITY_REFERENCE = 5,
83 XML_READER_TYPE_ENTITY = 6,
84 XML_READER_TYPE_PROCESSING_INSTRUCTION = 7,
85 XML_READER_TYPE_COMMENT = 8,
86 XML_READER_TYPE_DOCUMENT = 9,
87 XML_READER_TYPE_DOCUMENT_TYPE = 10,
88 XML_READER_TYPE_DOCUMENT_FRAGMENT = 11,
89 XML_READER_TYPE_NOTATION = 12,
90 XML_READER_TYPE_WHITESPACE = 13,
91 XML_READER_TYPE_SIGNIFICANT_WHITESPACE = 14,
92 XML_READER_TYPE_END_ELEMENT = 15,
93 XML_READER_TYPE_END_ENTITY = 16,
94 XML_READER_TYPE_XML_DECLARATION = 17
95 } xmlReaderTypes;
96
97 /**
98 * xmlTextReader:
99 *
100 * Structure for an xmlReader context.
101 */
102 typedef struct _xmlTextReader xmlTextReader;
103
104 /**
105 * xmlTextReaderPtr:
106 *
107 * Pointer to an xmlReader context.
108 */
109 typedef xmlTextReader *xmlTextReaderPtr;
110
111 /*
112 * Constructors & Destructor
113 */
114 XMLPUBFUN xmlTextReaderPtr
115 xmlNewTextReader (xmlParserInputBufferPtr input,
116 const char *URI);
117 XMLPUBFUN xmlTextReaderPtr
118 xmlNewTextReaderFilename(const char *URI);
119
120 XMLPUBFUN void
121 xmlFreeTextReader (xmlTextReaderPtr reader);
122
123 XMLPUBFUN int
124 xmlTextReaderSetup(xmlTextReaderPtr reader,
125 xmlParserInputBufferPtr input, const char *URL,
126 const char *encoding, int options);
127 XMLPUBFUN void
128 xmlTextReaderSetMaxAmplification(xmlTextReaderPtr reader,
129 unsigned maxAmpl);
130
131 /*
132 * Iterators
133 */
134 XMLPUBFUN int
135 xmlTextReaderRead (xmlTextReaderPtr reader);
136
137 #ifdef LIBXML_WRITER_ENABLED
138 XMLPUBFUN xmlChar *
139 xmlTextReaderReadInnerXml(xmlTextReaderPtr reader);
140
141 XMLPUBFUN xmlChar *
142 xmlTextReaderReadOuterXml(xmlTextReaderPtr reader);
143 #endif
144
145 XMLPUBFUN xmlChar *
146 xmlTextReaderReadString (xmlTextReaderPtr reader);
147 XMLPUBFUN int
148 xmlTextReaderReadAttributeValue(xmlTextReaderPtr reader);
149
150 /*
151 * Attributes of the node
152 */
153 XMLPUBFUN int
154 xmlTextReaderAttributeCount(xmlTextReaderPtr reader);
155 XMLPUBFUN int
156 xmlTextReaderDepth (xmlTextReaderPtr reader);
157 XMLPUBFUN int
158 xmlTextReaderHasAttributes(xmlTextReaderPtr reader);
159 XMLPUBFUN int
160 xmlTextReaderHasValue(xmlTextReaderPtr reader);
161 XMLPUBFUN int
162 xmlTextReaderIsDefault (xmlTextReaderPtr reader);
163 XMLPUBFUN int
164 xmlTextReaderIsEmptyElement(xmlTextReaderPtr reader);
165 XMLPUBFUN int
166 xmlTextReaderNodeType (xmlTextReaderPtr reader);
167 XMLPUBFUN int
168 xmlTextReaderQuoteChar (xmlTextReaderPtr reader);
169 XMLPUBFUN int
170 xmlTextReaderReadState (xmlTextReaderPtr reader);
171 XMLPUBFUN int
172 xmlTextReaderIsNamespaceDecl(xmlTextReaderPtr reader);
173
174 XMLPUBFUN const xmlChar *
175 xmlTextReaderConstBaseUri (xmlTextReaderPtr reader);
176 XMLPUBFUN const xmlChar *
177 xmlTextReaderConstLocalName (xmlTextReaderPtr reader);
178 XMLPUBFUN const xmlChar *
179 xmlTextReaderConstName (xmlTextReaderPtr reader);
180 XMLPUBFUN const xmlChar *
181 xmlTextReaderConstNamespaceUri(xmlTextReaderPtr reader);
182 XMLPUBFUN const xmlChar *
183 xmlTextReaderConstPrefix (xmlTextReaderPtr reader);
184 XMLPUBFUN const xmlChar *
185 xmlTextReaderConstXmlLang (xmlTextReaderPtr reader);
186 XMLPUBFUN const xmlChar *
187 xmlTextReaderConstString (xmlTextReaderPtr reader,
188 const xmlChar *str);
189 XMLPUBFUN const xmlChar *
190 xmlTextReaderConstValue (xmlTextReaderPtr reader);
191
192 /*
193 * use the Const version of the routine for
194 * better performance and simpler code
195 */
196 XMLPUBFUN xmlChar *
197 xmlTextReaderBaseUri (xmlTextReaderPtr reader);
198 XMLPUBFUN xmlChar *
199 xmlTextReaderLocalName (xmlTextReaderPtr reader);
200 XMLPUBFUN xmlChar *
201 xmlTextReaderName (xmlTextReaderPtr reader);
202 XMLPUBFUN xmlChar *
203 xmlTextReaderNamespaceUri(xmlTextReaderPtr reader);
204 XMLPUBFUN xmlChar *
205 xmlTextReaderPrefix (xmlTextReaderPtr reader);
206 XMLPUBFUN xmlChar *
207 xmlTextReaderXmlLang (xmlTextReaderPtr reader);
208 XMLPUBFUN xmlChar *
209 xmlTextReaderValue (xmlTextReaderPtr reader);
210
211 /*
212 * Methods of the XmlTextReader
213 */
214 XMLPUBFUN int
215 xmlTextReaderClose (xmlTextReaderPtr reader);
216 XMLPUBFUN xmlChar *
217 xmlTextReaderGetAttributeNo (xmlTextReaderPtr reader,
218 int no);
219 XMLPUBFUN xmlChar *
220 xmlTextReaderGetAttribute (xmlTextReaderPtr reader,
221 const xmlChar *name);
222 XMLPUBFUN xmlChar *
223 xmlTextReaderGetAttributeNs (xmlTextReaderPtr reader,
224 const xmlChar *localName,
225 const xmlChar *namespaceURI);
226 XMLPUBFUN xmlParserInputBufferPtr
227 xmlTextReaderGetRemainder (xmlTextReaderPtr reader);
228 XMLPUBFUN xmlChar *
229 xmlTextReaderLookupNamespace(xmlTextReaderPtr reader,
230 const xmlChar *prefix);
231 XMLPUBFUN int
232 xmlTextReaderMoveToAttributeNo(xmlTextReaderPtr reader,
233 int no);
234 XMLPUBFUN int
235 xmlTextReaderMoveToAttribute(xmlTextReaderPtr reader,
236 const xmlChar *name);
237 XMLPUBFUN int
238 xmlTextReaderMoveToAttributeNs(xmlTextReaderPtr reader,
239 const xmlChar *localName,
240 const xmlChar *namespaceURI);
241 XMLPUBFUN int
242 xmlTextReaderMoveToFirstAttribute(xmlTextReaderPtr reader);
243 XMLPUBFUN int
244 xmlTextReaderMoveToNextAttribute(xmlTextReaderPtr reader);
245 XMLPUBFUN int
246 xmlTextReaderMoveToElement (xmlTextReaderPtr reader);
247 XMLPUBFUN int
248 xmlTextReaderNormalization (xmlTextReaderPtr reader);
249 XMLPUBFUN const xmlChar *
250 xmlTextReaderConstEncoding (xmlTextReaderPtr reader);
251
252 /*
253 * Extensions
254 */
255 XMLPUBFUN int
256 xmlTextReaderSetParserProp (xmlTextReaderPtr reader,
257 int prop,
258 int value);
259 XMLPUBFUN int
260 xmlTextReaderGetParserProp (xmlTextReaderPtr reader,
261 int prop);
262 XMLPUBFUN xmlNodePtr
263 xmlTextReaderCurrentNode (xmlTextReaderPtr reader);
264
265 XMLPUBFUN int
266 xmlTextReaderGetParserLineNumber(xmlTextReaderPtr reader);
267
268 XMLPUBFUN int
269 xmlTextReaderGetParserColumnNumber(xmlTextReaderPtr reader);
270
271 XMLPUBFUN xmlNodePtr
272 xmlTextReaderPreserve (xmlTextReaderPtr reader);
273 #ifdef LIBXML_PATTERN_ENABLED
274 XMLPUBFUN int
275 xmlTextReaderPreservePattern(xmlTextReaderPtr reader,
276 const xmlChar *pattern,
277 const xmlChar **namespaces);
278 #endif /* LIBXML_PATTERN_ENABLED */
279 XMLPUBFUN xmlDocPtr
280 xmlTextReaderCurrentDoc (xmlTextReaderPtr reader);
281 XMLPUBFUN xmlNodePtr
282 xmlTextReaderExpand (xmlTextReaderPtr reader);
283 XMLPUBFUN int
284 xmlTextReaderNext (xmlTextReaderPtr reader);
285 XMLPUBFUN int
286 xmlTextReaderNextSibling (xmlTextReaderPtr reader);
287 XMLPUBFUN int
288 xmlTextReaderIsValid (xmlTextReaderPtr reader);
289 #ifdef LIBXML_SCHEMAS_ENABLED
290 XMLPUBFUN int
291 xmlTextReaderRelaxNGValidate(xmlTextReaderPtr reader,
292 const char *rng);
293 XMLPUBFUN int
294 xmlTextReaderRelaxNGValidateCtxt(xmlTextReaderPtr reader,
295 xmlRelaxNGValidCtxtPtr ctxt,
296 int options);
297
298 XMLPUBFUN int
299 xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader,
300 xmlRelaxNGPtr schema);
301 XMLPUBFUN int
302 xmlTextReaderSchemaValidate (xmlTextReaderPtr reader,
303 const char *xsd);
304 XMLPUBFUN int
305 xmlTextReaderSchemaValidateCtxt(xmlTextReaderPtr reader,
306 xmlSchemaValidCtxtPtr ctxt,
307 int options);
308 XMLPUBFUN int
309 xmlTextReaderSetSchema (xmlTextReaderPtr reader,
310 xmlSchemaPtr schema);
311 #endif
312 XMLPUBFUN const xmlChar *
313 xmlTextReaderConstXmlVersion(xmlTextReaderPtr reader);
314 XMLPUBFUN int
315 xmlTextReaderStandalone (xmlTextReaderPtr reader);
316
317
318 /*
319 * Index lookup
320 */
321 XMLPUBFUN long
322 xmlTextReaderByteConsumed (xmlTextReaderPtr reader);
323
324 /*
325 * New more complete APIs for simpler creation and reuse of readers
326 */
327 XMLPUBFUN xmlTextReaderPtr
328 xmlReaderWalker (xmlDocPtr doc);
329 XMLPUBFUN xmlTextReaderPtr
330 xmlReaderForDoc (const xmlChar * cur,
331 const char *URL,
332 const char *encoding,
333 int options);
334 XMLPUBFUN xmlTextReaderPtr
335 xmlReaderForFile (const char *filename,
336 const char *encoding,
337 int options);
338 XMLPUBFUN xmlTextReaderPtr
339 xmlReaderForMemory (const char *buffer,
340 int size,
341 const char *URL,
342 const char *encoding,
343 int options);
344 XMLPUBFUN xmlTextReaderPtr
345 xmlReaderForFd (int fd,
346 const char *URL,
347 const char *encoding,
348 int options);
349 XMLPUBFUN xmlTextReaderPtr
350 xmlReaderForIO (xmlInputReadCallback ioread,
351 xmlInputCloseCallback ioclose,
352 void *ioctx,
353 const char *URL,
354 const char *encoding,
355 int options);
356
357 XMLPUBFUN int
358 xmlReaderNewWalker (xmlTextReaderPtr reader,
359 xmlDocPtr doc);
360 XMLPUBFUN int
361 xmlReaderNewDoc (xmlTextReaderPtr reader,
362 const xmlChar * cur,
363 const char *URL,
364 const char *encoding,
365 int options);
366 XMLPUBFUN int
367 xmlReaderNewFile (xmlTextReaderPtr reader,
368 const char *filename,
369 const char *encoding,
370 int options);
371 XMLPUBFUN int
372 xmlReaderNewMemory (xmlTextReaderPtr reader,
373 const char *buffer,
374 int size,
375 const char *URL,
376 const char *encoding,
377 int options);
378 XMLPUBFUN int
379 xmlReaderNewFd (xmlTextReaderPtr reader,
380 int fd,
381 const char *URL,
382 const char *encoding,
383 int options);
384 XMLPUBFUN int
385 xmlReaderNewIO (xmlTextReaderPtr reader,
386 xmlInputReadCallback ioread,
387 xmlInputCloseCallback ioclose,
388 void *ioctx,
389 const char *URL,
390 const char *encoding,
391 int options);
392 /*
393 * Error handling extensions
394 */
395 typedef void * xmlTextReaderLocatorPtr;
396
397 /**
398 * xmlTextReaderErrorFunc:
399 * @arg: the user argument
400 * @msg: the message
401 * @severity: the severity of the error
402 * @locator: a locator indicating where the error occurred
403 *
404 * Signature of an error callback from a reader parser
405 */
406 typedef void (*xmlTextReaderErrorFunc)(void *arg,
407 const char *msg,
408 xmlParserSeverities severity,
409 xmlTextReaderLocatorPtr locator);
410 XMLPUBFUN int
411 xmlTextReaderLocatorLineNumber(xmlTextReaderLocatorPtr locator);
412 XMLPUBFUN xmlChar *
413 xmlTextReaderLocatorBaseURI (xmlTextReaderLocatorPtr locator);
414 XMLPUBFUN void
415 xmlTextReaderSetErrorHandler(xmlTextReaderPtr reader,
416 xmlTextReaderErrorFunc f,
417 void *arg);
418 XMLPUBFUN void
419 xmlTextReaderSetStructuredErrorHandler(xmlTextReaderPtr reader,
420 xmlStructuredErrorFunc f,
421 void *arg);
422 XMLPUBFUN void
423 xmlTextReaderGetErrorHandler(xmlTextReaderPtr reader,
424 xmlTextReaderErrorFunc *f,
425 void **arg);
426
427 #endif /* LIBXML_READER_ENABLED */
428
429 #ifdef __cplusplus
430 }
431 #endif
432
433 #endif /* __XML_XMLREADER_H__ */
434