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