xmlreader.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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. XMLPUBFUN const xmlError *
  118. xmlTextReaderGetLastError(xmlTextReaderPtr reader);
  119. /*
  120. * Iterators
  121. */
  122. XMLPUBFUN int
  123. xmlTextReaderRead (xmlTextReaderPtr reader);
  124. #ifdef LIBXML_WRITER_ENABLED
  125. XMLPUBFUN xmlChar *
  126. xmlTextReaderReadInnerXml(xmlTextReaderPtr reader);
  127. XMLPUBFUN xmlChar *
  128. xmlTextReaderReadOuterXml(xmlTextReaderPtr reader);
  129. #endif
  130. XMLPUBFUN xmlChar *
  131. xmlTextReaderReadString (xmlTextReaderPtr reader);
  132. XMLPUBFUN int
  133. xmlTextReaderReadAttributeValue(xmlTextReaderPtr reader);
  134. /*
  135. * Attributes of the node
  136. */
  137. XMLPUBFUN int
  138. xmlTextReaderAttributeCount(xmlTextReaderPtr reader);
  139. XMLPUBFUN int
  140. xmlTextReaderDepth (xmlTextReaderPtr reader);
  141. XMLPUBFUN int
  142. xmlTextReaderHasAttributes(xmlTextReaderPtr reader);
  143. XMLPUBFUN int
  144. xmlTextReaderHasValue(xmlTextReaderPtr reader);
  145. XMLPUBFUN int
  146. xmlTextReaderIsDefault (xmlTextReaderPtr reader);
  147. XMLPUBFUN int
  148. xmlTextReaderIsEmptyElement(xmlTextReaderPtr reader);
  149. XMLPUBFUN int
  150. xmlTextReaderNodeType (xmlTextReaderPtr reader);
  151. XMLPUBFUN int
  152. xmlTextReaderQuoteChar (xmlTextReaderPtr reader);
  153. XMLPUBFUN int
  154. xmlTextReaderReadState (xmlTextReaderPtr reader);
  155. XMLPUBFUN int
  156. xmlTextReaderIsNamespaceDecl(xmlTextReaderPtr reader);
  157. XMLPUBFUN const xmlChar *
  158. xmlTextReaderConstBaseUri (xmlTextReaderPtr reader);
  159. XMLPUBFUN const xmlChar *
  160. xmlTextReaderConstLocalName (xmlTextReaderPtr reader);
  161. XMLPUBFUN const xmlChar *
  162. xmlTextReaderConstName (xmlTextReaderPtr reader);
  163. XMLPUBFUN const xmlChar *
  164. xmlTextReaderConstNamespaceUri(xmlTextReaderPtr reader);
  165. XMLPUBFUN const xmlChar *
  166. xmlTextReaderConstPrefix (xmlTextReaderPtr reader);
  167. XMLPUBFUN const xmlChar *
  168. xmlTextReaderConstXmlLang (xmlTextReaderPtr reader);
  169. XMLPUBFUN const xmlChar *
  170. xmlTextReaderConstString (xmlTextReaderPtr reader,
  171. const xmlChar *str);
  172. XMLPUBFUN const xmlChar *
  173. xmlTextReaderConstValue (xmlTextReaderPtr reader);
  174. /*
  175. * use the Const version of the routine for
  176. * better performance and simpler code
  177. */
  178. XMLPUBFUN xmlChar *
  179. xmlTextReaderBaseUri (xmlTextReaderPtr reader);
  180. XMLPUBFUN xmlChar *
  181. xmlTextReaderLocalName (xmlTextReaderPtr reader);
  182. XMLPUBFUN xmlChar *
  183. xmlTextReaderName (xmlTextReaderPtr reader);
  184. XMLPUBFUN xmlChar *
  185. xmlTextReaderNamespaceUri(xmlTextReaderPtr reader);
  186. XMLPUBFUN xmlChar *
  187. xmlTextReaderPrefix (xmlTextReaderPtr reader);
  188. XMLPUBFUN xmlChar *
  189. xmlTextReaderXmlLang (xmlTextReaderPtr reader);
  190. XMLPUBFUN xmlChar *
  191. xmlTextReaderValue (xmlTextReaderPtr reader);
  192. /*
  193. * Methods of the XmlTextReader
  194. */
  195. XMLPUBFUN int
  196. xmlTextReaderClose (xmlTextReaderPtr reader);
  197. XMLPUBFUN xmlChar *
  198. xmlTextReaderGetAttributeNo (xmlTextReaderPtr reader,
  199. int no);
  200. XMLPUBFUN xmlChar *
  201. xmlTextReaderGetAttribute (xmlTextReaderPtr reader,
  202. const xmlChar *name);
  203. XMLPUBFUN xmlChar *
  204. xmlTextReaderGetAttributeNs (xmlTextReaderPtr reader,
  205. const xmlChar *localName,
  206. const xmlChar *namespaceURI);
  207. XMLPUBFUN xmlParserInputBufferPtr
  208. xmlTextReaderGetRemainder (xmlTextReaderPtr reader);
  209. XMLPUBFUN xmlChar *
  210. xmlTextReaderLookupNamespace(xmlTextReaderPtr reader,
  211. const xmlChar *prefix);
  212. XMLPUBFUN int
  213. xmlTextReaderMoveToAttributeNo(xmlTextReaderPtr reader,
  214. int no);
  215. XMLPUBFUN int
  216. xmlTextReaderMoveToAttribute(xmlTextReaderPtr reader,
  217. const xmlChar *name);
  218. XMLPUBFUN int
  219. xmlTextReaderMoveToAttributeNs(xmlTextReaderPtr reader,
  220. const xmlChar *localName,
  221. const xmlChar *namespaceURI);
  222. XMLPUBFUN int
  223. xmlTextReaderMoveToFirstAttribute(xmlTextReaderPtr reader);
  224. XMLPUBFUN int
  225. xmlTextReaderMoveToNextAttribute(xmlTextReaderPtr reader);
  226. XMLPUBFUN int
  227. xmlTextReaderMoveToElement (xmlTextReaderPtr reader);
  228. XMLPUBFUN int
  229. xmlTextReaderNormalization (xmlTextReaderPtr reader);
  230. XMLPUBFUN const xmlChar *
  231. xmlTextReaderConstEncoding (xmlTextReaderPtr reader);
  232. /*
  233. * Extensions
  234. */
  235. XMLPUBFUN int
  236. xmlTextReaderSetParserProp (xmlTextReaderPtr reader,
  237. int prop,
  238. int value);
  239. XMLPUBFUN int
  240. xmlTextReaderGetParserProp (xmlTextReaderPtr reader,
  241. int prop);
  242. XMLPUBFUN xmlNodePtr
  243. xmlTextReaderCurrentNode (xmlTextReaderPtr reader);
  244. XMLPUBFUN int
  245. xmlTextReaderGetParserLineNumber(xmlTextReaderPtr reader);
  246. XMLPUBFUN int
  247. xmlTextReaderGetParserColumnNumber(xmlTextReaderPtr reader);
  248. XMLPUBFUN xmlNodePtr
  249. xmlTextReaderPreserve (xmlTextReaderPtr reader);
  250. #ifdef LIBXML_PATTERN_ENABLED
  251. XMLPUBFUN int
  252. xmlTextReaderPreservePattern(xmlTextReaderPtr reader,
  253. const xmlChar *pattern,
  254. const xmlChar **namespaces);
  255. #endif /* LIBXML_PATTERN_ENABLED */
  256. XMLPUBFUN xmlDocPtr
  257. xmlTextReaderCurrentDoc (xmlTextReaderPtr reader);
  258. XMLPUBFUN xmlNodePtr
  259. xmlTextReaderExpand (xmlTextReaderPtr reader);
  260. XMLPUBFUN int
  261. xmlTextReaderNext (xmlTextReaderPtr reader);
  262. XMLPUBFUN int
  263. xmlTextReaderNextSibling (xmlTextReaderPtr reader);
  264. XMLPUBFUN int
  265. xmlTextReaderIsValid (xmlTextReaderPtr reader);
  266. #ifdef LIBXML_SCHEMAS_ENABLED
  267. XMLPUBFUN int
  268. xmlTextReaderRelaxNGValidate(xmlTextReaderPtr reader,
  269. const char *rng);
  270. XMLPUBFUN int
  271. xmlTextReaderRelaxNGValidateCtxt(xmlTextReaderPtr reader,
  272. xmlRelaxNGValidCtxtPtr ctxt,
  273. int options);
  274. XMLPUBFUN int
  275. xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader,
  276. xmlRelaxNGPtr schema);
  277. XMLPUBFUN int
  278. xmlTextReaderSchemaValidate (xmlTextReaderPtr reader,
  279. const char *xsd);
  280. XMLPUBFUN int
  281. xmlTextReaderSchemaValidateCtxt(xmlTextReaderPtr reader,
  282. xmlSchemaValidCtxtPtr ctxt,
  283. int options);
  284. XMLPUBFUN int
  285. xmlTextReaderSetSchema (xmlTextReaderPtr reader,
  286. xmlSchemaPtr schema);
  287. #endif
  288. XMLPUBFUN const xmlChar *
  289. xmlTextReaderConstXmlVersion(xmlTextReaderPtr reader);
  290. XMLPUBFUN int
  291. xmlTextReaderStandalone (xmlTextReaderPtr reader);
  292. /*
  293. * Index lookup
  294. */
  295. XMLPUBFUN long
  296. xmlTextReaderByteConsumed (xmlTextReaderPtr reader);
  297. /*
  298. * New more complete APIs for simpler creation and reuse of readers
  299. */
  300. XMLPUBFUN xmlTextReaderPtr
  301. xmlReaderWalker (xmlDocPtr doc);
  302. XMLPUBFUN xmlTextReaderPtr
  303. xmlReaderForDoc (const xmlChar * cur,
  304. const char *URL,
  305. const char *encoding,
  306. int options);
  307. XMLPUBFUN xmlTextReaderPtr
  308. xmlReaderForFile (const char *filename,
  309. const char *encoding,
  310. int options);
  311. XMLPUBFUN xmlTextReaderPtr
  312. xmlReaderForMemory (const char *buffer,
  313. int size,
  314. const char *URL,
  315. const char *encoding,
  316. int options);
  317. XMLPUBFUN xmlTextReaderPtr
  318. xmlReaderForFd (int fd,
  319. const char *URL,
  320. const char *encoding,
  321. int options);
  322. XMLPUBFUN xmlTextReaderPtr
  323. xmlReaderForIO (xmlInputReadCallback ioread,
  324. xmlInputCloseCallback ioclose,
  325. void *ioctx,
  326. const char *URL,
  327. const char *encoding,
  328. int options);
  329. XMLPUBFUN int
  330. xmlReaderNewWalker (xmlTextReaderPtr reader,
  331. xmlDocPtr doc);
  332. XMLPUBFUN int
  333. xmlReaderNewDoc (xmlTextReaderPtr reader,
  334. const xmlChar * cur,
  335. const char *URL,
  336. const char *encoding,
  337. int options);
  338. XMLPUBFUN int
  339. xmlReaderNewFile (xmlTextReaderPtr reader,
  340. const char *filename,
  341. const char *encoding,
  342. int options);
  343. XMLPUBFUN int
  344. xmlReaderNewMemory (xmlTextReaderPtr reader,
  345. const char *buffer,
  346. int size,
  347. const char *URL,
  348. const char *encoding,
  349. int options);
  350. XMLPUBFUN int
  351. xmlReaderNewFd (xmlTextReaderPtr reader,
  352. int fd,
  353. const char *URL,
  354. const char *encoding,
  355. int options);
  356. XMLPUBFUN int
  357. xmlReaderNewIO (xmlTextReaderPtr reader,
  358. xmlInputReadCallback ioread,
  359. xmlInputCloseCallback ioclose,
  360. void *ioctx,
  361. const char *URL,
  362. const char *encoding,
  363. int options);
  364. /*
  365. * Error handling extensions
  366. */
  367. typedef void * xmlTextReaderLocatorPtr;
  368. /**
  369. * xmlTextReaderErrorFunc:
  370. * @arg: the user argument
  371. * @msg: the message
  372. * @severity: the severity of the error
  373. * @locator: a locator indicating where the error occurred
  374. *
  375. * Signature of an error callback from a reader parser
  376. */
  377. typedef void (*xmlTextReaderErrorFunc)(void *arg,
  378. const char *msg,
  379. xmlParserSeverities severity,
  380. xmlTextReaderLocatorPtr locator);
  381. XMLPUBFUN int
  382. xmlTextReaderLocatorLineNumber(xmlTextReaderLocatorPtr locator);
  383. XMLPUBFUN xmlChar *
  384. xmlTextReaderLocatorBaseURI (xmlTextReaderLocatorPtr locator);
  385. XMLPUBFUN void
  386. xmlTextReaderSetErrorHandler(xmlTextReaderPtr reader,
  387. xmlTextReaderErrorFunc f,
  388. void *arg);
  389. XMLPUBFUN void
  390. xmlTextReaderSetStructuredErrorHandler(xmlTextReaderPtr reader,
  391. xmlStructuredErrorFunc f,
  392. void *arg);
  393. XMLPUBFUN void
  394. xmlTextReaderGetErrorHandler(xmlTextReaderPtr reader,
  395. xmlTextReaderErrorFunc *f,
  396. void **arg);
  397. #endif /* LIBXML_READER_ENABLED */
  398. #ifdef __cplusplus
  399. }
  400. #endif
  401. #endif /* __XML_XMLREADER_H__ */