00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef LIBAEGIS_XMLTEXTREAD_H
00021 #define LIBAEGIS_XMLTEXTREAD_H
00022
00023 #include <libxml/xmlreader.h>
00024 #include <libxml/xmlversion.h>
00025
00026 #if LIBXML_VERSION < 20510
00027 enum xmlReaderTypes
00028 {
00029 XML_READER_TYPE_NONE = 0,
00030 XML_READER_TYPE_ELEMENT = 1,
00031 XML_READER_TYPE_ATTRIBUTE = 2,
00032 XML_READER_TYPE_TEXT = 3,
00033 XML_READER_TYPE_CDATA = 4,
00034 XML_READER_TYPE_ENTITY_REFERENCE = 5,
00035 XML_READER_TYPE_ENTITY = 6,
00036 XML_READER_TYPE_PROCESSING_INSTRUCTION = 7,
00037 XML_READER_TYPE_COMMENT = 8,
00038 XML_READER_TYPE_DOCUMENT = 9,
00039 XML_READER_TYPE_DOCUMENT_TYPE = 10,
00040 XML_READER_TYPE_DOCUMENT_FRAGMENT = 11,
00041 XML_READER_TYPE_NOTATION = 12,
00042 XML_READER_TYPE_WHITESPACE = 13,
00043 XML_READER_TYPE_SIGNIFICANT_WHITESPACE = 14,
00044 XML_READER_TYPE_END_ELEMENT = 15,
00045 XML_READER_TYPE_END_ENTITY = 16,
00046 XML_READER_TYPE_XML_DECLARATION = 17
00047 };
00048 #endif
00049
00050 #include <libaegis/input.h>
00051
00056 class xml_text_reader
00057 {
00058 public:
00062 virtual ~xml_text_reader();
00063
00067 xml_text_reader(input &deeper, bool validate = false);
00068
00073 void parse();
00074
00075 protected:
00081 virtual void process_node() = 0;
00082
00093 virtual void process_node_end(bool empty);
00094
00102 int depth() { return xmlTextReaderDepth(reader); }
00103
00114 xmlReaderTypes
00115 node_type()
00116 {
00117 return (xmlReaderTypes)xmlTextReaderNodeType(reader);
00118 }
00119
00124 static const char *xmlReaderType_ename(xmlReaderTypes);
00125
00133 const xmlChar *name() { return xmlTextReaderName(reader); }
00134
00142 int is_empty_element() { return xmlTextReaderIsEmptyElement(reader); }
00143
00151 int has_value() { return xmlTextReaderHasValue(reader); }
00152
00161 const xmlChar *value() { return xmlTextReaderValue(reader); }
00162
00168 void move_back_to_element() { xmlTextReaderMoveToElement(reader); }
00169
00170 private:
00175 input deeper;
00176
00181 xmlTextReaderPtr reader;
00182
00188 int number_of_errors;
00189
00195 static int number_of_parsers;
00196
00201 bool validate;
00202
00207 static int read_callback(void *context, char *buffer, int len);
00208
00213 int read_deeper(char *buffer, int len);
00214
00219 static int close_callback(void *context);
00220
00225 void close();
00226
00231 static void error_callback(void *context, const char *msg,
00232 xmlParserSeverities severity, xmlTextReaderLocatorPtr locator);
00233
00238 void error(const char *msg, xmlParserSeverities severity,
00239 xmlTextReaderLocatorPtr locator);
00240
00251 bool read();
00252
00256 xml_text_reader();
00257
00261 xml_text_reader(const xml_text_reader &);
00262
00266 xml_text_reader &operator=(const xml_text_reader &);
00267 };
00268
00269 #endif // LIBAEGIS_XMLTEXTREAD_H