xmlreader.h 12 KB

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