You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

428 lines
12 KiB

4 years ago
  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. xmlTextReaderRelaxNGValidateCtxt(xmlTextReaderPtr reader,
  264. xmlRelaxNGValidCtxtPtr ctxt,
  265. int options);
  266. XMLPUBFUN int XMLCALL
  267. xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader,
  268. xmlRelaxNGPtr schema);
  269. XMLPUBFUN int XMLCALL
  270. xmlTextReaderSchemaValidate (xmlTextReaderPtr reader,
  271. const char *xsd);
  272. XMLPUBFUN int XMLCALL
  273. xmlTextReaderSchemaValidateCtxt(xmlTextReaderPtr reader,
  274. xmlSchemaValidCtxtPtr ctxt,
  275. int options);
  276. XMLPUBFUN int XMLCALL
  277. xmlTextReaderSetSchema (xmlTextReaderPtr reader,
  278. xmlSchemaPtr schema);
  279. #endif
  280. XMLPUBFUN const xmlChar * XMLCALL
  281. xmlTextReaderConstXmlVersion(xmlTextReaderPtr reader);
  282. XMLPUBFUN int XMLCALL
  283. xmlTextReaderStandalone (xmlTextReaderPtr reader);
  284. /*
  285. * Index lookup
  286. */
  287. XMLPUBFUN long XMLCALL
  288. xmlTextReaderByteConsumed (xmlTextReaderPtr reader);
  289. /*
  290. * New more complete APIs for simpler creation and reuse of readers
  291. */
  292. XMLPUBFUN xmlTextReaderPtr XMLCALL
  293. xmlReaderWalker (xmlDocPtr doc);
  294. XMLPUBFUN xmlTextReaderPtr XMLCALL
  295. xmlReaderForDoc (const xmlChar * cur,
  296. const char *URL,
  297. const char *encoding,
  298. int options);
  299. XMLPUBFUN xmlTextReaderPtr XMLCALL
  300. xmlReaderForFile (const char *filename,
  301. const char *encoding,
  302. int options);
  303. XMLPUBFUN xmlTextReaderPtr XMLCALL
  304. xmlReaderForMemory (const char *buffer,
  305. int size,
  306. const char *URL,
  307. const char *encoding,
  308. int options);
  309. XMLPUBFUN xmlTextReaderPtr XMLCALL
  310. xmlReaderForFd (int fd,
  311. const char *URL,
  312. const char *encoding,
  313. int options);
  314. XMLPUBFUN xmlTextReaderPtr XMLCALL
  315. xmlReaderForIO (xmlInputReadCallback ioread,
  316. xmlInputCloseCallback ioclose,
  317. void *ioctx,
  318. const char *URL,
  319. const char *encoding,
  320. int options);
  321. XMLPUBFUN int XMLCALL
  322. xmlReaderNewWalker (xmlTextReaderPtr reader,
  323. xmlDocPtr doc);
  324. XMLPUBFUN int XMLCALL
  325. xmlReaderNewDoc (xmlTextReaderPtr reader,
  326. const xmlChar * cur,
  327. const char *URL,
  328. const char *encoding,
  329. int options);
  330. XMLPUBFUN int XMLCALL
  331. xmlReaderNewFile (xmlTextReaderPtr reader,
  332. const char *filename,
  333. const char *encoding,
  334. int options);
  335. XMLPUBFUN int XMLCALL
  336. xmlReaderNewMemory (xmlTextReaderPtr reader,
  337. const char *buffer,
  338. int size,
  339. const char *URL,
  340. const char *encoding,
  341. int options);
  342. XMLPUBFUN int XMLCALL
  343. xmlReaderNewFd (xmlTextReaderPtr reader,
  344. int fd,
  345. const char *URL,
  346. const char *encoding,
  347. int options);
  348. XMLPUBFUN int XMLCALL
  349. xmlReaderNewIO (xmlTextReaderPtr reader,
  350. xmlInputReadCallback ioread,
  351. xmlInputCloseCallback ioclose,
  352. void *ioctx,
  353. const char *URL,
  354. const char *encoding,
  355. int options);
  356. /*
  357. * Error handling extensions
  358. */
  359. typedef void * xmlTextReaderLocatorPtr;
  360. /**
  361. * xmlTextReaderErrorFunc:
  362. * @arg: the user argument
  363. * @msg: the message
  364. * @severity: the severity of the error
  365. * @locator: a locator indicating where the error occurred
  366. *
  367. * Signature of an error callback from a reader parser
  368. */
  369. typedef void (XMLCALL *xmlTextReaderErrorFunc)(void *arg,
  370. const char *msg,
  371. xmlParserSeverities severity,
  372. xmlTextReaderLocatorPtr locator);
  373. XMLPUBFUN int XMLCALL
  374. xmlTextReaderLocatorLineNumber(xmlTextReaderLocatorPtr locator);
  375. XMLPUBFUN xmlChar * XMLCALL
  376. xmlTextReaderLocatorBaseURI (xmlTextReaderLocatorPtr locator);
  377. XMLPUBFUN void XMLCALL
  378. xmlTextReaderSetErrorHandler(xmlTextReaderPtr reader,
  379. xmlTextReaderErrorFunc f,
  380. void *arg);
  381. XMLPUBFUN void XMLCALL
  382. xmlTextReaderSetStructuredErrorHandler(xmlTextReaderPtr reader,
  383. xmlStructuredErrorFunc f,
  384. void *arg);
  385. XMLPUBFUN void XMLCALL
  386. xmlTextReaderGetErrorHandler(xmlTextReaderPtr reader,
  387. xmlTextReaderErrorFunc *f,
  388. void **arg);
  389. #endif /* LIBXML_READER_ENABLED */
  390. #ifdef __cplusplus
  391. }
  392. #endif
  393. #endif /* __XML_XMLREADER_H__ */