Showing content from http://www.ncbi.nlm.nih.gov/IEB/ToolBox/CPP_DOC/doxyhtml/classxml_1_1event__parser.html below:
NCBI C++ ToolKit: xml::event_parser Class Reference
Search Toolkit Book for xml::event_parser
The xml::event_parser is used to parse an XML document by calling member functions when certain things in the XML document are parsed. More...
#include <misc/xmlwrapp/event_parser.hpp>
enum sax_handlers {
start_document_handler = (1 << 0) , end_document_handler = (1 << 1) , start_element_handler = (1 << 2) , end_element_handler = (1 << 3) ,
characters_handler = (1 << 4) , pi_handler = (1 << 5) , comment_handler = (1 << 6) , cdata_handler = (1 << 7) ,
notation_decl_handler = (1 << 8) , entity_decl_handler = (1 << 9) , unparsed_entity_decl_handler = (1 << 10) , external_subset_handler = (1 << 11) ,
internal_subset_handler = (1 << 12) , attribute_decl_handler = (1 << 13) , element_decl_handler = (1 << 14) , reference_handler = (1 << 15) ,
default_set
} The enumeration defines control bits to on/off specific SAX parser handlers. More...
typedef std::map< std::string, std::string > attrs_type a type for holding XML node attributes More...
typedef std::size_t size_type size type More...
typedef std::vector< std::string > values_type a type for holding attribute declaration values More...
typedef int sax_handlers_mask handlers mask type More...
enum entity_type {
type_internal_general_entity , type_external_general_parsed_entity , type_external_general_unparsed_entity , type_internal_parameter_entity ,
type_external_parameter_entity , type_internal_predefined_entity
} enum for different types of XML entities More...
enum attribute_type {
type_attribute_cdata , type_attribute_id , type_attribute_idref , type_attribute_idrefs ,
type_attribute_entity , type_attribute_entities , type_attribute_nmtoken , type_attribute_nmtokens ,
type_attribute_enumeration , type_attribute_notation
} enum for different types of XML attributes More...
enum attribute_default_type { type_attribute_none , type_attribute_required , type_attribute_implied , type_attribute_fixed } enum for different default attribute definition More...
enum element_content_type {
type_undefined , type_empty , type_any , type_mixed ,
type_element
} enum for element content types More...
virtual bool start_document () Override this member function to receive the start_document message. More...
virtual bool end_document () Override this member function to receive the end_document message. More...
virtual bool start_element (const std::string &name, const attrs_type &attrs)=0 Override this member function to receive the start_element message. More...
virtual bool end_element (const std::string &name)=0 Override this member function to receive the end_element message. More...
virtual bool text (const std::string &contents)=0 Override this member function to receive the text message. More...
virtual bool cdata (const std::string &contents) Override this member function to receive the cdata mesage. More...
virtual bool processing_instruction (const std::string &target, const std::string &data) Override this member function to receive the procesing_instruction message. More...
virtual bool comment (const std::string &contents) Override this member function to receive the comment message. More...
virtual bool warning (const std::string &message) Override this memeber function to receive parser warnings. More...
virtual bool error (const std::string &message) Override this memeber function to receive parser errors. More...
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. More...
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. More...
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. More...
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. More...
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. More...
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. More...
virtual bool element_declaration (const std::string &name, element_content_type type, _xmlElementContent *content) Override this memeber function to receive the element declaration message. More...
virtual bool entity_reference (const std::string &name) Override this memeber function to receive the entity reference message. More...
The xml::event_parser is used to parse an XML document by calling member functions when certain things in the XML document are parsed.
In order to use this class you derive a sub-class from it and override the protected virtual functions.
Definition at line 78 of file event_parser.hpp.
◆ attrs_type ◆ sax_handlers_mask ◆ size_type ◆ values_type
a type for holding attribute declaration values
Definition at line 117 of file event_parser.hpp.
◆ attribute_default_type
enum for different default attribute definition
Enumerator type_attribute_none type_attribute_required type_attribute_implied type_attribute_fixed
Definition at line 278 of file event_parser.hpp.
◆ attribute_type
enum for different types of XML attributes
Enumerator type_attribute_cdata type_attribute_id type_attribute_idref type_attribute_idrefs type_attribute_entity type_attribute_entities type_attribute_nmtoken type_attribute_nmtokens type_attribute_enumeration type_attribute_notation
Definition at line 264 of file event_parser.hpp.
◆ element_content_type
enum for element content types
Enumerator type_undefined type_empty type_any type_mixed type_element
Definition at line 286 of file event_parser.hpp.
◆ entity_type
enum for different types of XML entities
Enumerator type_internal_general_entity type_external_general_parsed_entity type_external_general_unparsed_entity type_internal_parameter_entity type_external_parameter_entity type_internal_predefined_entity
Definition at line 254 of file event_parser.hpp.
◆ sax_handlers
The enumeration defines control bits to on/off specific SAX parser handlers.
Enumerator start_document_handler
controls the start document handler
end_document_handler
controls the end document handler
start_element_handler
controls the start element handler
end_element_handler
controls the end element handler
characters_handler
controls the text handler
pi_handler
controls the processing instruction handler
comment_handler
controls the comment handler
cdata_handler
controls the cdata handler
notation_decl_handler
controls the notation declaration handler
entity_decl_handler
controls the entity declaration handler
unparsed_entity_decl_handler
controls the unparsed entity declaration handler
external_subset_handler
controls the external subset handler
internal_subset_handler
controls the internal subset handler
attribute_decl_handler
controls the attribute declaration handler
element_decl_handler
controls the element declaration handler
reference_handler
controls the reference handler
default_set
Set of the control bits which makes the event_parser bahave exactly the way it was in original xmlwrapp 0.6.0.
Definition at line 84 of file event_parser.hpp.
◆ event_parser() [1/3]
xml::event_parser class constructor.
-
Parameters
-
mask The handlers mask. Default value makes it compatible with xmlwrapp 0.6.0.
-
Note
-
The default mask switches on 6 handlers. If your code uses a subset of handlers (say, 3 out of 6) and uses the default mask the code might be not 100% optimal. The performance will be lower than it could be. It is caused by conversion between libxml2 and C++ datatypes. The arguments will be converted even for those handlers which are not used in your code. So, to get the best performance, use an explicit mask for handlers which you are actually interested in.
Definition at line 282 of file event_parser.cpp.
References mask, and pimpl_.
◆ ~event_parser() xml::event_parser::~event_parser ( void ) virtual ◆ event_parser() [2/3]
Moving constrctor.
-
Parameters
-
other The other event parser.
Definition at line 291 of file event_parser.cpp.
References NULL.
◆ event_parser() [3/3] ◆ attribute_declaration()
Override this memeber function to receive the attribute declaration message.
-
Parameters
-
element_name The element name. attribute_name The attribute full name. attr_type The attribute type. default_type The attribute default value type. default_value The attribute default value. default_values The attribute possible default values.
-
Returns
-
You should return true to continue parsing.
-
Return false if you want to stop.
-
Note
-
If an exception is generated in the overloaded version of the member it will be intercepted and two actions will take place:
- a fatal error message will be stored in the messages contaner. The message text is taken from .what() if the generated exception derives from std::exception, otherwise a generic error message is generated.
- parsing of the document will be stopped. So check the completion status and the error messages after any usage of the parse*() family members.
Definition at line 524 of file event_parser.cpp.
Referenced by xml::impl::epimpl::event_attribute_declaration().
◆ cdata()
Override this member function to receive the cdata mesage.
This member function is called when the parser encounters a section in the XML data.
The default implementation just calls the text() member function to handle the text inside the CDATA section.
-
Parameters
-
contents The contents of the CDATA section.
-
Returns
-
You should return true to continue parsing.
-
Return false if you want to stop.
-
Note
-
If an exception is generated in the overloaded version of the member it will be intercepted and two actions will take place:
- a fatal error message will be stored in the messages contaner. The message text is taken from .what() if the generated exception derives from std::exception, otherwise a generic error message is generated.
- parsing of the document will be stopped. So check the completion status and the error messages after any usage of the parse*() family members.
-
Author
-
Peter Jones
Definition at line 487 of file event_parser.cpp.
References text().
Referenced by xml::impl::epimpl::event_cdata().
◆ comment()
Override this member function to receive the comment message.
This member function will be called when the XML parser encounters a comment .
The default implementation will ignore XML comments and return true.
-
Parameters
-
contents The contents of the XML comment.
-
Returns
-
You should return true to continue parsing.
-
Return false if you want to stop.
-
Note
-
If an exception is generated in the overloaded version of the member it will be intercepted and two actions will take place:
- a fatal error message will be stored in the messages contaner. The message text is taken from .what() if the generated exception derives from std::exception, otherwise a generic error message is generated.
- parsing of the document will be stopped. So check the completion status and the error messages after any usage of the parse*() family members.
-
Author
-
Peter Jones
Definition at line 483 of file event_parser.cpp.
Referenced by xml::impl::epimpl::event_comment().
◆ element_declaration()
Override this memeber function to receive the element declaration message.
-
Parameters
-
name The element name. type The element content type. content The raw libxml2 structure pointer.
-
Returns
-
You should return true to continue parsing.
-
Return false if you want to stop.
-
Note
-
If an exception is generated in the overloaded version of the member it will be intercepted and two actions will take place:
- a fatal error message will be stored in the messages contaner. The message text is taken from .what() if the generated exception derives from std::exception, otherwise a generic error message is generated.
- parsing of the document will be stopped. So check the completion status and the error messages after any usage of the parse*() family members.
Definition at line 533 of file event_parser.cpp.
Referenced by xml::impl::epimpl::event_element_declaration().
◆ end_document() bool xml::event_parser::end_document ( ) protectedvirtual
Override this member function to receive the end_document message.
This member function is called when the document end has been detected.
-
Returns
-
You should return true to continue parsing; false to stop.
-
Note
-
If an exception is generated in the overloaded version of the member it will be intercepted and two actions will take place:
- a fatal error message will be stored in the messages contaner. The message text is taken from .what() if the generated exception derives from std::exception, otherwise a generic error message is generated.
- parsing of the document will be stopped. So check the completion status and the error messages after any usage of the parse*() family members.
Definition at line 475 of file event_parser.cpp.
Referenced by xml::impl::epimpl::event_end_document().
◆ end_element()
Override this member function to receive the end_element message.
This member function is called when the parser encounters the closing of an element.
-
Parameters
-
name The name of the element that was closed.
-
Returns
-
You should return true to continue parsing; false to stop.
-
Note
-
If an exception is generated in the overloaded version of the member it will be intercepted and two actions will take place:
- a fatal error message will be stored in the messages contaner. The message text is taken from .what() if the generated exception derives from std::exception, otherwise a generic error message is generated.
- parsing of the document will be stopped. So check the completion status and the error messages after any usage of the parse*() family members.
-
Author
-
Peter Jones
Referenced by xml::impl::epimpl::event_end_element().
◆ entity_declaration()
Override this memeber function to receive the entity declaration message.
This member function will be called when the XML parser encounters <!ENTITY ...> declaration.
-
Parameters
-
name The name of the entity. type The type of the entity. public_id The public ID of the entity. system_id The system ID of the entity. content The entity value.
-
Returns
-
You should return true to continue parsing.
-
Return false if you want to stop.
-
Note
-
If an exception is generated in the overloaded version of the member it will be intercepted and two actions will take place:
- a fatal error message will be stored in the messages contaner. The message text is taken from .what() if the generated exception derives from std::exception, otherwise a generic error message is generated.
- parsing of the document will be stopped. So check the completion status and the error messages after any usage of the parse*() family members.
Definition at line 516 of file event_parser.cpp.
Referenced by xml::impl::epimpl::event_entity_declaration().
◆ entity_reference()
Override this memeber function to receive the entity reference message.
-
Parameters
-
name The entity reference name.
-
Returns
-
You should return true to continue parsing.
-
Return false if you want to stop.
-
Note
-
the callback appears straight after the 'text' callback (if the gobal setting to substutute entities is set to false, see xml::init::substitute_entities(bool)). The preceding 'text' callback delivers a substituted named entity value.
-
see http://mail.gnome.org/archives/xml/2009-May/msg00006.html and http://xmlsoft.org/entities.html for more details when you get errors on entity reference parsing
-
If an exception is generated in the overloaded version of the member it will be intercepted and two actions will take place:
- a fatal error message will be stored in the messages contaner. The message text is taken from .what() if the generated exception derives from std::exception, otherwise a generic error message is generated.
- parsing of the document will be stopped. So check the completion status and the error messages after any usage of the parse*() family members.
Definition at line 539 of file event_parser.cpp.
Referenced by xml::impl::epimpl::event_entity_reference().
◆ error()
Override this memeber function to receive parser errors.
The default behaviour is to stop parsing. Note: There could also be fatal errors. The parser will save such fatal errors in the list (which is available by calling get_parser_messages() member) and will stop parsing.
-
Parameters
-
message The error message from the parser.
-
Returns
-
You should return true to continue parsing.
-
Return false if you want to stop.
-
Note
-
If an exception is generated in the overloaded version of the member it will be intercepted and two actions will take place:
- a fatal error message will be stored in the messages contaner. The message text is taken from .what() if the generated exception derives from std::exception, otherwise a generic error message is generated.
- parsing of the document will be stopped. So check the completion status and the error messages after any usage of the parse*() family members.
Definition at line 547 of file event_parser.cpp.
Referenced by xml::impl::epimpl::event_error().
◆ external_subset_declaration()
Override this memeber function to receive the external subset declaration message.
-
Parameters
-
name The root element name. external_id The external ID. public_id The public ID.
-
Returns
-
You should return true to continue parsing.
-
Return false if you want to stop.
-
Note
-
If an exception is generated in the overloaded version of the member it will be intercepted and two actions will take place:
- a fatal error message will be stored in the messages contaner. The message text is taken from .what() if the generated exception derives from std::exception, otherwise a generic error message is generated.
- parsing of the document will be stopped. So check the completion status and the error messages after any usage of the parse*() family members.
Definition at line 504 of file event_parser.cpp.
Referenced by xml::impl::epimpl::event_external_subset_declaration().
◆ get_attribute_default_type() ◆ get_attribute_type() ◆ get_element_content_type() ◆ get_entity_type() ◆ internal_subset_declaration()
Override this memeber function to receive the internal subset declaration message.
-
Parameters
-
name The root element name. external_id The external ID. public_id The public ID.
-
Returns
-
You should return true to continue parsing.
-
Return false if you want to stop.
-
Note
-
If an exception is generated in the overloaded version of the member it will be intercepted and two actions will take place:
- a fatal error message will be stored in the messages contaner. The message text is taken from .what() if the generated exception derives from std::exception, otherwise a generic error message is generated.
- parsing of the document will be stopped. So check the completion status and the error messages after any usage of the parse*() family members.
Definition at line 510 of file event_parser.cpp.
Referenced by xml::impl::epimpl::event_internal_subset_declaration().
◆ is_failure() ◆ notation_declaration()
Override this memeber function to receive the notation declaration message.
This member function will be called when the XML parser encounters <!NOTATION ...> declaration.
-
Parameters
-
name The name of the notation. public_id The public ID of the entity. system_id The system ID of the entity.
-
Returns
-
You should return true to continue parsing.
-
Return false if you want to stop.
-
Note
-
If an exception is generated in the overloaded version of the member it will be intercepted and two actions will take place:
- a fatal error message will be stored in the messages contaner. The message text is taken from .what() if the generated exception derives from std::exception, otherwise a generic error message is generated.
- parsing of the document will be stopped. So check the completion status and the error messages after any usage of the parse*() family members.
Definition at line 491 of file event_parser.cpp.
Referenced by xml::impl::epimpl::event_notation_declaration().
◆ operator=() [1/2] ◆ operator=() [2/2] ◆ parse_chunk()
Call this function to parse a chunk of xml data.
When you are done feeding the parser chunks of data you need to call the parse_finish member function. If an error was detected while a chunk was parsed or a callback returned false to stop parsing the parse_finish member function should also be called.
-
Parameters
-
chunk The xml data chuck to parse. messages A pointer to the object where all the warnings and error messages are collected. If NULL then no messages will be collected. how How to treat warnings (default: warnings are not treated as errors). If warnings are treated as errors false is returned in case of both errors and/or warnings. If warnings are not treated as errors then false is returned only when there are errors. length The size of the given data chunk
-
Returns
-
True if the chunk was parsed sucessfully and was not interrupted by the user; false otherwise.
-
Exceptions
-
Throws xml::exception in case if missed parse_finish call is detected.
-
Author
-
Peter Jones
Definition at line 386 of file event_parser.cpp.
References xml::impl::clear_https_messages(), xml::impl::collect_https_messages(), xml::impl::epimpl::create_context(), xml::impl::epimpl::errors_, xml::error_messages::get_messages(), is_failure(), NULL, parse_finished_, xml::impl::epimpl::parser_context_, xml::impl::epimpl::parser_status_, pimpl_, and xml::size_t_to_int_conversion().
Referenced by parse_stream().
◆ parse_file()
Call this member function to parse the given file.
-
Parameters
-
filename The name of the file to parse. messages A pointer to the object where all the warnings and error messages are collected. If NULL then no messages will be collected. how How to treat warnings (default: warnings are not treated as errors). If warnings are treated as errors false is returned in case of both errors and/or warnings. If warnings are not treated as errors then false is returned only when there are errors.
-
Returns
-
True if the file was successfully parsed and was not interrupted by the user; false otherwise.
-
Author
-
Peter Jones
Definition at line 309 of file event_parser.cpp.
References file, file_name, xml::error_messages::get_messages(), NULL, parse_finish(), parse_finished_, parse_stream(), xml::impl::epimpl::parser_status_, pimpl_, string, and xml::error_message::type_error.
Referenced by CEutilsClient::x_LinkOnceT().
◆ parse_finish() ◆ parse_stream()
Parse what ever data that can be read from the given stream.
-
Parameters
-
stream The stream to read data from. messages A pointer to the object where all the warnings and error messages are collected. If NULL then no messages will be collected. how How to treat warnings (default: warnings are not treated as errors). If warnings are treated as errors false is returned in case of both errors and/or warnings. If warnings are not treated as errors then false is returned only when there are errors.
-
Returns
-
True if the stream was successfully parsed and was not interrupted by the user; false otherwise.
-
Author
-
Peter Jones
Definition at line 338 of file event_parser.cpp.
References buffer, const_buffer_size, xml::impl::epimpl::errors_, xml::error_messages::get_messages(), parse_chunk(), parse_finish(), parse_finished_, xml::impl::epimpl::parser_status_, pimpl_, xml::impl::epimpl::recreate_context(), and xml::error_message::type_error.
Referenced by CPMCIDConverterServer::GetPmids(), parse_file(), CHydraServer::RunHydraSearch(), CEUtilsGeneric::TryQuery(), CEutilsClient::x_CountOnce(), CEutilsClient::x_LinkOnceT(), and CEutilsClient::x_ParseSearchResults().
◆ processing_instruction()
Override this member function to receive the procesing_instruction message.
This member function will be called when the XML parser encounters a processing instruction <?target data?>.
The default implementation will ignore processing instructions and return true.
-
Parameters
-
target The target of the processing instruction data The data of the processing instruction.
-
Returns
-
You should return true to continue parsing.
-
Return false if you want to stop.
-
Note
-
If an exception is generated in the overloaded version of the member it will be intercepted and two actions will take place:
- a fatal error message will be stored in the messages contaner. The message text is taken from .what() if the generated exception derives from std::exception, otherwise a generic error message is generated.
- parsing of the document will be stopped. So check the completion status and the error messages after any usage of the parse*() family members.
-
Author
-
Peter Jones
Definition at line 479 of file event_parser.cpp.
Referenced by xml::impl::epimpl::event_pi().
◆ start_document() bool xml::event_parser::start_document ( ) protectedvirtual
Override this member function to receive the start_document message.
This member function is called when the document start is being processed.
-
Returns
-
You should return true to continue parsing; false to stop.
-
Note
-
If an exception is generated in the overloaded version of the member it will be intercepted and two actions will take place:
- a fatal error message will be stored in the messages contaner. The message text is taken from .what() if the generated exception derives from std::exception, otherwise a generic error message is generated.
- parsing of the document will be stopped. So check the completion status and the error messages after any usage of the parse*() family members.
Definition at line 471 of file event_parser.cpp.
Referenced by xml::impl::epimpl::event_start_document().
◆ start_element()
Override this member function to receive the start_element message.
This member function is called when the parser encounters an xml element.
-
Parameters
-
name The name of the element attrs The element's attributes
-
Returns
-
You should return true to continue parsing; false to stop.
-
Note
-
If an exception is generated in the overloaded version of the member it will be intercepted and two actions will take place:
- a fatal error message will be stored in the messages contaner. The message text is taken from .what() if the generated exception derives from std::exception, otherwise a generic error message is generated.
- parsing of the document will be stopped. So check the completion status and the error messages after any usage of the parse*() family members.
-
Author
-
Peter Jones
Referenced by xml::impl::epimpl::event_start_element().
◆ text()
Override this member function to receive the text message.
This member function is called when the parser encounters text nodes.
-
Parameters
-
contents The contents of the text node.
-
Returns
-
You should return true to continue parsing; false to stop.
-
Note
-
In case of named entities the callback will have the substituted entity value and the 'entity_reference' callback may follow it (see the 'entity_reference' callback notes).
-
If an exception is generated in the overloaded version of the member it will be intercepted and two actions will take place:
- a fatal error message will be stored in the messages contaner. The message text is taken from .what() if the generated exception derives from std::exception, otherwise a generic error message is generated.
- parsing of the document will be stopped. So check the completion status and the error messages after any usage of the parse*() family members.
-
Author
-
Peter Jones
Referenced by xml::impl::epimpl::event_text().
◆ unparsed_entity_declaration()
Override this memeber function to receive the unparsed entity declaration message.
-
Parameters
-
name The name of the entity. public_id The public ID of the entity. system_id The system ID of the entity. notation_name The notation name.
-
Returns
-
You should return true to continue parsing.
-
Return false if you want to stop.
-
Note
-
If an exception is generated in the overloaded version of the member it will be intercepted and two actions will take place:
- a fatal error message will be stored in the messages contaner. The message text is taken from .what() if the generated exception derives from std::exception, otherwise a generic error message is generated.
- parsing of the document will be stopped. So check the completion status and the error messages after any usage of the parse*() family members.
Definition at line 497 of file event_parser.cpp.
Referenced by xml::impl::epimpl::event_unparsed_entity_declaration().
◆ warning()
Override this memeber function to receive parser warnings.
The default behaviour is to ignore warnings.
-
Parameters
-
message The warning message from the parser.
-
Returns
-
You should return true to continue parsing.
-
Return false if you want to stop.
-
Note
-
If an exception is generated in the overloaded version of the member it will be intercepted and two actions will take place:
- a fatal error message will be stored in the messages contaner. The message text is taken from .what() if the generated exception derives from std::exception, otherwise a generic error message is generated.
- parsing of the document will be stopped. So check the completion status and the error messages after any usage of the parse*() family members.
-
Author
-
Peter Jones
Definition at line 543 of file event_parser.cpp.
Referenced by xml::impl::epimpl::event_warning().
◆ impl::epimpl ◆ parse_finished_ bool xml::event_parser::parse_finished_ private ◆ pimpl_
The documentation for this class was generated from the following files:
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4