47 # pragma warning(disable : 4786)
58 #include <libxml/parser.h>
59 #include <libxml/xmlversion.h>
77 #if LIBXML_VERSION >= 20600
78 # define initxmlDefaultSAXHandler xmlSAX2InitDefaultSAXHandler
79 # include <libxml/SAX2.h>
107 void event_pi (
const xmlChar *target,
const xmlChar *data);
111 const xmlChar *public_id,
112 const xmlChar *system_id);
115 const xmlChar * publicId,
116 const xmlChar * systemId,
119 const xmlChar *public_id,
120 const xmlChar *system_id,
121 const xmlChar *notation_name);
123 const xmlChar *external_id,
124 const xmlChar *system_id);
126 const xmlChar *external_id,
127 const xmlChar *system_id);
129 const xmlChar *attribute_name,
132 const xmlChar *default_value,
133 xmlEnumeration *default_values);
136 xmlElementContent *content);
152 {
static_cast<epimpl*
>(parser)->event_start_document(); }
155 {
static_cast<epimpl*
>(parser)->event_end_document(); }
158 {
static_cast<epimpl*
>(parser)->event_start_element(
tag, props); }
161 {
static_cast<epimpl*
>(parser)->event_end_element(
tag); }
163 static void cb_text (
void *parser,
const xmlChar *
text,
int length)
164 {
static_cast<epimpl*
>(parser)->event_text(
text, length); }
166 static void cb_pi (
void *parser,
const xmlChar *target,
const xmlChar *data)
167 {
static_cast<epimpl*
>(parser)->event_pi(target, data); }
170 {
static_cast<epimpl*
>(parser)->event_comment(
text); }
173 {
static_cast<epimpl*
>(parser)->event_cdata(
text, length); }
176 const xmlChar *public_id,
177 const xmlChar *system_id)
178 {
static_cast<epimpl*
>(parser)->event_notation_declaration(name,
183 int type,
const xmlChar *public_id,
184 const xmlChar *system_id,
186 {
static_cast<epimpl*
>(parser)->event_entity_declaration(name,
194 const xmlChar *public_id,
195 const xmlChar *system_id,
196 const xmlChar *notation_name)
197 {
static_cast<epimpl*
>(parser)->event_unparsed_entity_declaration(name,
204 const xmlChar *external_id,
205 const xmlChar *system_id)
206 {
static_cast<epimpl*
>(parser)->event_external_subset_declaration(name,
212 const xmlChar *external_id,
213 const xmlChar *system_id)
214 {
static_cast<epimpl*
>(parser)->event_internal_subset_declaration(name,
219 const xmlChar *element_name,
220 const xmlChar *attribute_name,
223 const xmlChar *default_value,
224 xmlEnumeration *default_values)
225 {
static_cast<epimpl*
>(parser)->event_attribute_declaration(element_name,
233 const xmlChar *element_name,
235 xmlElementContent *content)
236 {
static_cast<epimpl*
>(parser)->event_element_declaration(element_name,
241 {
static_cast<epimpl*
>(parser)->event_entity_reference(name); }
243 static void cb_warning (
void *parser,
const char *message, ...) {
247 va_start(ap, message);
251 static_cast<epimpl*
>(parser)->event_warning(complete_message);
254 static void cb_error (
void *parser,
const char *message, ...) {
258 va_start(ap, message);
262 static_cast<epimpl*
>(parser)->event_error(complete_message);
269 va_start(ap, message);
273 static_cast<epimpl*
>(parser)->event_fatal_error(complete_message);
299 if (
this != &other) {
318 std::ifstream
file(filename);
325 if (filename !=
NULL)
342 std::unique_ptr<error_messages> msgs;
358 if (stream && (stream.eof() ||
359 stream.peek() == std::istream::traits_type::eof()))
375 (
size_t)stream.gcount(),
378 if (!stream && !stream.eof())
390 std::unique_ptr<error_messages> msgs;
412 "an error occured or the user "
413 "stopped the parser");
418 "after the parser has finished");
424 "chunk is too large to parse"), 0);
438 std::unique_ptr<error_messages> msgs;
488 return text(contents);
535 _xmlElementContent *content) {
553 case XML_INTERNAL_GENERAL_ENTITY:
return type_internal_general_entity;
554 case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
return type_external_general_parsed_entity;
555 case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
return type_external_general_unparsed_entity;
556 case XML_INTERNAL_PARAMETER_ENTITY:
return type_internal_parameter_entity;
557 case XML_EXTERNAL_PARAMETER_ENTITY:
return type_external_parameter_entity;
558 case XML_INTERNAL_PREDEFINED_ENTITY:
return type_internal_predefined_entity;
566 case XML_ATTRIBUTE_CDATA:
return type_attribute_cdata;
567 case XML_ATTRIBUTE_ID:
return type_attribute_id;
568 case XML_ATTRIBUTE_IDREF:
return type_attribute_idref;
569 case XML_ATTRIBUTE_IDREFS:
return type_attribute_idrefs;
570 case XML_ATTRIBUTE_ENTITY:
return type_attribute_entity;
571 case XML_ATTRIBUTE_ENTITIES:
return type_attribute_entities;
572 case XML_ATTRIBUTE_NMTOKEN:
return type_attribute_nmtoken;
573 case XML_ATTRIBUTE_NMTOKENS:
return type_attribute_nmtokens;
574 case XML_ATTRIBUTE_ENUMERATION:
return type_attribute_enumeration;
575 case XML_ATTRIBUTE_NOTATION:
return type_attribute_notation;
583 case XML_ATTRIBUTE_NONE:
return type_attribute_none;
584 case XML_ATTRIBUTE_REQUIRED:
return type_attribute_required;
585 case XML_ATTRIBUTE_IMPLIED:
return type_attribute_implied;
586 case XML_ATTRIBUTE_FIXED:
return type_attribute_fixed;
595 case XML_ELEMENT_TYPE_EMPTY:
return type_empty;
596 case XML_ELEMENT_TYPE_ANY:
return type_any;
597 case XML_ELEMENT_TYPE_MIXED:
return type_mixed;
598 case XML_ELEMENT_TYPE_ELEMENT:
return type_element;
605 : parser_context_(
NULL),
606 parser_status_(
true),
685 throw std::bad_alloc();
704 const xmlChar **attrp;
706 for (attrp = props; attrp && *attrp; attrp += 2) {
707 attrs[
reinterpret_cast<const char*
>(*attrp)] =
reinterpret_cast<const char*
>(*(attrp+1));
712 }
catch (
const std::exception &ex) {
728 }
catch (
const std::exception &ex) {
742 std::string contents(
reinterpret_cast<const char*
>(
text),
static_cast<std::string::size_type
>(length));
744 }
catch (
const std::exception &ex) {
759 }
catch (
const std::exception &ex) {
774 }
catch (
const std::exception &ex) {
788 std::string s_target =
reinterpret_cast<const char*
>(target);
789 std::string s_data =
reinterpret_cast<const char*
>(data);
791 }
catch (
const std::exception &ex) {
807 }
catch (
const std::exception &ex) {
821 std::string contents(
reinterpret_cast<const char*
>(
text),
static_cast<std::string::size_type
>(length));
823 }
catch (
const std::exception &ex) {
834 const xmlChar *public_id,
835 const xmlChar *system_id) {
839 std::string notation_name( name ?
reinterpret_cast<const char*
>(name) :
"" );
840 std::string notation_public_id( public_id ?
reinterpret_cast<const char*
>(public_id) :
"" );
841 std::string notation_system_id( system_id ?
reinterpret_cast<const char*
>(system_id) :
"" );
845 }
catch (
const std::exception &ex) {
857 const xmlChar *public_id,
858 const xmlChar *system_id,
864 std::string entity_public_id( public_id ?
reinterpret_cast<const char*
>(public_id) :
"" );
865 std::string entity_system_id( system_id ?
reinterpret_cast<const char*
>(system_id) :
"" );
866 std::string entity_content( content ?
reinterpret_cast<const char*
>(content) :
"" );
868 entity_public_id, entity_system_id,
870 }
catch (
const std::exception &ex) {
881 const xmlChar *public_id,
882 const xmlChar *system_id,
883 const xmlChar *notation_name) {
888 std::string entity_public_id( public_id ?
reinterpret_cast<const char*
>(public_id) :
"" );
889 std::string entity_system_id( system_id ?
reinterpret_cast<const char*
>(system_id) :
"" );
890 std::string entity_notation_name( notation_name ?
reinterpret_cast<const char*
>(notation_name) :
"" );
892 entity_public_id, entity_system_id,
893 entity_notation_name);
894 }
catch (
const std::exception &ex) {
905 const xmlChar *external_id,
906 const xmlChar *system_id) {
910 std::string root_element_name( name ?
reinterpret_cast<const char*
>(name) :
"" );
911 std::string ext_id( external_id ?
reinterpret_cast<const char*
>(external_id) :
"" );
912 std::string sys_id( system_id ?
reinterpret_cast<const char*
>(system_id) :
"" );
916 }
catch (
const std::exception &ex) {
927 const xmlChar *external_id,
928 const xmlChar *system_id) {
932 std::string root_element_name( name ?
reinterpret_cast<const char*
>(name) :
"" );
933 std::string ext_id( external_id ?
reinterpret_cast<const char*
>(external_id) :
"" );
934 std::string sys_id( system_id ?
reinterpret_cast<const char*
>(system_id) :
"" );
938 }
catch (
const std::exception &ex) {
949 const xmlChar *attribute_name,
952 const xmlChar *default_value,
953 xmlEnumeration *default_values) {
957 std::string element( element_name ?
reinterpret_cast<const char*
>(element_name) :
"" );
958 std::string attr_name( attribute_name ?
reinterpret_cast<const char*
>(attribute_name) :
"" );
959 std::string default_val( default_value ?
reinterpret_cast<const char*
>(default_value) :
"" );
962 while (default_values) {
963 if (default_values->name)
964 def_vals.push_back(
std::string(
reinterpret_cast<const char*
>(default_values->name)));
965 default_values = default_values->next;
972 }
catch (
const std::exception &ex) {
984 xmlElementContent *content) {
988 std::string element( element_name ?
reinterpret_cast<const char*
>(element_name) :
"" );
993 }
catch (
const std::exception &ex) {
1007 std::string reference_name( name ?
reinterpret_cast<const char*
>(name) :
"" );
1010 }
catch (
const std::exception &ex) {
1023 long line = xmlLastError.line;
1027 if (xmlLastError.file !=
NULL)
1028 filename = xmlLastError.file;
1035 }
catch (
const std::exception &ex) {
1048 long line = xmlLastError.line;
1052 if (xmlLastError.file !=
NULL)
1053 filename = xmlLastError.file;
1060 }
catch (
const std::exception &ex) {
1074 long line = xmlLastError.line;
1078 if (xmlLastError.file !=
NULL)
1079 filename = xmlLastError.file;
The xml::error_message class is used to store a single error message which may appear while parsing o...
@ type_fatal_error
fatal error
The xml::error_messages class is used to store all the error message which are collected while parsin...
bool has_fatal_errors(void) const
Check if there are fatal errors in the error messages.
const error_messages_type & get_messages(void) const
Get the error messages.
bool has_warnings(void) const
Check if there are warnings in the error messages.
bool has_errors(void) const
Check if there are errors in the error messages.
The xml::event_parser is used to parse an XML document by calling member functions when certain thing...
entity_type get_entity_type(int)
std::map< std::string, std::string > attrs_type
a type for holding XML node attributes
attribute_default_type get_attribute_default_type(int)
event_parser & operator=(event_parser &&other)
Moving assignment.
attribute_default_type
enum for different default attribute definition
virtual bool unparsed_entity_declaration(const std::string &name, const std::string &public_id, const std::string &system_id, const std::string ¬ation_name)
Override this memeber function to receive the unparsed entity declaration message.
bool parse_finish(error_messages *messages, warnings_as_errors_type how=type_warnings_not_errors)
Finish parsing chunked data.
virtual bool external_subset_declaration(const std::string &name, const std::string &external_id, const std::string &system_id)
Override this memeber function to receive the external subset declaration message.
attribute_type get_attribute_type(int)
std::vector< std::string > values_type
a type for holding attribute declaration values
bool parse_stream(std::istream &stream, error_messages *messages, warnings_as_errors_type how=type_warnings_not_errors)
Parse what ever data that can be read from the given stream.
virtual bool text(const std::string &contents)=0
Override this member function to receive the text message.
virtual bool attribute_declaration(const std::string &element_name, const std::string &attribute_name, attribute_type attr_type, attribute_default_type default_type, const std::string &default_value, const values_type &default_values)
Override this memeber function to receive the attribute declaration message.
virtual bool start_document()
Override this member function to receive the start_document message.
virtual bool cdata(const std::string &contents)
Override this member function to receive the cdata mesage.
bool is_failure(error_messages *messages, warnings_as_errors_type how) const
virtual bool internal_subset_declaration(const std::string &name, const std::string &external_id, const std::string &system_id)
Override this memeber function to receive the internal subset declaration message.
@ notation_decl_handler
controls the notation declaration handler
@ end_element_handler
controls the end element handler
@ comment_handler
controls the comment handler
@ element_decl_handler
controls the element declaration handler
@ unparsed_entity_decl_handler
controls the unparsed entity declaration handler
@ entity_decl_handler
controls the entity declaration handler
@ internal_subset_handler
controls the internal subset handler
@ external_subset_handler
controls the external subset handler
@ attribute_decl_handler
controls the attribute declaration handler
@ pi_handler
controls the processing instruction handler
@ start_element_handler
controls the start element handler
@ cdata_handler
controls the cdata handler
@ reference_handler
controls the reference handler
@ start_document_handler
controls the start document handler
@ characters_handler
controls the text handler
@ end_document_handler
controls the end document handler
virtual bool element_declaration(const std::string &name, element_content_type type, _xmlElementContent *content)
Override this memeber function to receive the element declaration message.
virtual bool end_element(const std::string &name)=0
Override this member function to receive the end_element message.
virtual bool start_element(const std::string &name, const attrs_type &attrs)=0
Override this member function to receive the start_element message.
int sax_handlers_mask
handlers mask type
virtual bool end_document()
Override this member function to receive the end_document message.
virtual bool warning(const std::string &message)
Override this memeber function to receive parser warnings.
virtual bool entity_reference(const std::string &name)
Override this memeber function to receive the entity reference message.
event_parser(sax_handlers_mask mask=default_set)
xml::event_parser class constructor.
virtual bool entity_declaration(const std::string &name, entity_type type, const std::string &public_id, const std::string &system_id, const std::string &content)
Override this memeber function to receive the entity declaration message.
element_content_type get_element_content_type(int)
entity_type
enum for different types of XML entities
virtual bool notation_declaration(const std::string &name, const std::string &public_id, const std::string &system_id)
Override this memeber function to receive the notation declaration message.
bool parse_chunk(const char *chunk, size_type length, error_messages *messages, warnings_as_errors_type how=type_warnings_not_errors)
Call this function to parse a chunk of xml data.
virtual bool error(const std::string &message)
Override this memeber function to receive parser errors.
virtual bool comment(const std::string &contents)
Override this member function to receive the comment message.
attribute_type
enum for different types of XML attributes
bool parse_file(const char *filename, error_messages *messages, warnings_as_errors_type how=type_warnings_not_errors)
Call this member function to parse the given file.
element_content_type
enum for element content types
virtual ~event_parser(void)
xml::event_parser class destructor.
std::size_t size_type
size type
virtual bool processing_instruction(const std::string &target, const std::string &data)
Override this member function to receive the procesing_instruction message.
This exception class is thrown by xmlwrapp for all runtime XML-related errors along with the xml::par...
static void cb_pi(void *parser, const xmlChar *target, const xmlChar *data)
static void cb_cdata(void *parser, const xmlChar *text, int length)
static void cb_start_element(void *parser, const xmlChar *tag, const xmlChar **props)
static void cb_external_subset_declaration(void *parser, const xmlChar *name, const xmlChar *external_id, const xmlChar *system_id)
static void cb_end_element(void *parser, const xmlChar *tag)
static void cb_entity_declaration(void *parser, const xmlChar *name, int type, const xmlChar *public_id, const xmlChar *system_id, xmlChar *content)
static void cb_unparsed_entity_declaration(void *parser, const xmlChar *name, const xmlChar *public_id, const xmlChar *system_id, const xmlChar *notation_name)
static void cb_attribute_declaration(void *parser, const xmlChar *element_name, const xmlChar *attribute_name, int attr_type, int default_type, const xmlChar *default_value, xmlEnumeration *default_values)
static void cb_element_declaration(void *parser, const xmlChar *element_name, int type, xmlElementContent *content)
static void cb_text(void *parser, const xmlChar *text, int length)
static void cb_end_document(void *parser)
static void cb_internal_subset_declaration(void *parser, const xmlChar *name, const xmlChar *external_id, const xmlChar *system_id)
static void cb_start_document(void *parser)
static void cb_error(void *parser, const char *message,...)
static void cb_fatal_error(void *parser, const char *message,...)
static void cb_ignore(void *, const xmlChar *, int)
static void cb_entity_reference(void *parser, const xmlChar *name)
static void cb_warning(void *parser, const char *message,...)
static void cb_comment(void *parser, const xmlChar *text)
static void cb_notation_declaration(void *parser, const xmlChar *name, const xmlChar *public_id, const xmlChar *system_id)
This file contains the definition of the xml::event_parser class.
static void text(MDB_val *v)
static const std::size_t const_buffer_size
This file contains the definition of the xml::exception class.
This file contains the definition of the xml::node class.
void clear_https_messages(void)
void printf2string(std::string &s, const char *message, va_list ap)
void collect_https_messages(xml::error_messages &append_to)
warnings_as_errors_type
A type for different approaches to process warnings.
@ type_warnings_are_errors
Treat warnings as errors.
int size_t_to_int_conversion(std::size_t value, const std::string &msg)
static pcre_uint8 * buffer
void event_entity_declaration(const xmlChar *name, int type, const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
void event_internal_subset_declaration(const xmlChar *name, const xmlChar *external_id, const xmlChar *system_id)
void event_external_subset_declaration(const xmlChar *name, const xmlChar *external_id, const xmlChar *system_id)
void recreate_context(void)
void event_warning(const std::string &message)
epimpl(event_parser &parent, event_parser::sax_handlers_mask mask)
void event_unparsed_entity_declaration(const xmlChar *name, const xmlChar *public_id, const xmlChar *system_id, const xmlChar *notation_name)
void event_fatal_error(const std::string &message)
void event_start_document(void)
void event_end_document(void)
epimpl & operator=(const epimpl &)
void event_attribute_declaration(const xmlChar *element_name, const xmlChar *attribute_name, int attr_type, int default_type, const xmlChar *default_value, xmlEnumeration *default_values)
xmlParserCtxt * parser_context_
void event_end_element(const xmlChar *tag)
void event_text(const xmlChar *text, int length)
void event_element_declaration(const xmlChar *element_name, int type, xmlElementContent *content)
void event_error(const std::string &message)
void create_context(void)
void event_comment(const xmlChar *text)
void event_pi(const xmlChar *target, const xmlChar *data)
void destroy_context(void)
void event_start_element(const xmlChar *tag, const xmlChar **props)
void event_entity_reference(const xmlChar *name)
void event_notation_declaration(const xmlChar *name, const xmlChar *public_id, const xmlChar *system_id)
void event_cdata(const xmlChar *text, int length)
xmlSAXHandler sax_handler_