xmlreader.h 12 KB

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