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