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