|
Aegis
4.25.D505
|
00001 // 00002 // aegis - project change supervisor 00003 // Copyright (C) 2005, 2006, 2008, 2012 Peter Miller 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 3 of the License, or (at 00008 // your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 00019 #ifndef LIBAEGIS_XMLTEXTREAD_H 00020 #define LIBAEGIS_XMLTEXTREAD_H 00021 00022 #include <libxml/xmlreader.h> 00023 #include <libxml/xmlversion.h> 00024 00025 #if LIBXML_VERSION < 20510 00026 enum xmlReaderTypes 00027 { 00028 XML_READER_TYPE_NONE = 0, 00029 XML_READER_TYPE_ELEMENT = 1, 00030 XML_READER_TYPE_ATTRIBUTE = 2, 00031 XML_READER_TYPE_TEXT = 3, 00032 XML_READER_TYPE_CDATA = 4, 00033 XML_READER_TYPE_ENTITY_REFERENCE = 5, 00034 XML_READER_TYPE_ENTITY = 6, 00035 XML_READER_TYPE_PROCESSING_INSTRUCTION = 7, 00036 XML_READER_TYPE_COMMENT = 8, 00037 XML_READER_TYPE_DOCUMENT = 9, 00038 XML_READER_TYPE_DOCUMENT_TYPE = 10, 00039 XML_READER_TYPE_DOCUMENT_FRAGMENT = 11, 00040 XML_READER_TYPE_NOTATION = 12, 00041 XML_READER_TYPE_WHITESPACE = 13, 00042 XML_READER_TYPE_SIGNIFICANT_WHITESPACE = 14, 00043 XML_READER_TYPE_END_ELEMENT = 15, 00044 XML_READER_TYPE_END_ENTITY = 16, 00045 XML_READER_TYPE_XML_DECLARATION = 17 00046 }; 00047 #endif 00048 00049 #include <libaegis/input.h> 00050 00055 class xml_text_reader 00056 { 00057 public: 00061 virtual ~xml_text_reader(); 00062 00066 xml_text_reader(input &deeper, bool validate = false); 00067 00072 void parse(void); 00073 00074 protected: 00080 virtual void process_node(void) = 0; 00081 00092 virtual void process_node_end(bool empty); 00093 00101 int depth(void) { return xmlTextReaderDepth(reader); } 00102 00113 xmlReaderTypes 00114 node_type(void) 00115 { 00116 return (xmlReaderTypes)xmlTextReaderNodeType(reader); 00117 } 00118 00123 static const char *xmlReaderType_ename(xmlReaderTypes); 00124 00132 const xmlChar *name(void) { return xmlTextReaderName(reader); } 00133 00141 int is_empty_element(void) { return xmlTextReaderIsEmptyElement(reader); } 00142 00150 int has_value(void) { return xmlTextReaderHasValue(reader); } 00151 00160 const xmlChar *value(void) { return xmlTextReaderValue(reader); } 00161 00167 void move_back_to_element(void) { xmlTextReaderMoveToElement(reader); } 00168 00169 private: 00174 input deeper; 00175 00180 xmlTextReaderPtr reader; 00181 00187 int number_of_errors; 00188 00194 static int number_of_parsers; 00195 00200 bool validate; 00201 00206 static int read_callback(void *context, char *buffer, int len); 00207 00212 int read_deeper(char *buffer, int len); 00213 00218 static int close_callback(void *context); 00219 00224 void close(void); 00225 00230 static void error_callback(void *context, const char *msg, 00231 xmlParserSeverities severity, xmlTextReaderLocatorPtr locator); 00232 00237 void error(const char *msg, xmlParserSeverities severity, 00238 xmlTextReaderLocatorPtr locator); 00239 00250 bool read(void); 00251 00255 xml_text_reader(); 00256 00260 xml_text_reader(const xml_text_reader &); 00261 00265 xml_text_reader &operator=(const xml_text_reader &); 00266 }; 00267 00268 #endif // LIBAEGIS_XMLTEXTREAD_H 00269 // vim: set ts=8 sw=4 et :
1.7.6.1