libxml++  5.4.0
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
xmlpp::Parser Class Referenceabstract

XML parser. More...

#include <libxml++/parsers/parser.h>

Inheritance diagram for xmlpp::Parser:
Inheritance graph
[legend]

Public Types

using size_type = unsigned int
 

Public Member Functions

 Parser ()
 
 ~Parser () override
 
bool get_include_default_attributes () const noexcept
 See set_include_default_attributes(). More...
 
void get_parser_options (int & set_options, int & clear_options) const noexcept
 See set_parser_options(). More...
 
bool get_substitute_entities () const noexcept
 See set_substitute_entities(). More...
 
bool get_throw_messages () const noexcept
 See set_throw_messages(). More...
 
bool get_validate () const noexcept
 See set_validate(). More...
 
virtual void parse_file (const std::string & filename)=0
 Parse an XML document from a file. More...
 
virtual void parse_memory (const ustring & contents)=0
 Parse an XML document from a string. More...
 
virtual void parse_memory_raw (const unsigned char * contents, size_type bytes_count)=0
 Parse an XML document from raw memory. More...
 
virtual void parse_stream (std::istream & in)=0
 Parse an XML document from a stream. More...
 
void set_include_default_attributes (bool val=true) noexcept
 Set whether default attribute values from the DTD shall be included in the node tree. More...
 
void set_parser_options (int set_options=0, int clear_options=0) noexcept
 Set and/or clear parser option flags. More...
 
void set_substitute_entities (bool val=true) noexcept
 Set whether the parser will automatically substitute entity references with the text of the entities' definitions. More...
 
void set_throw_messages (bool val=true) noexcept
 Set whether the parser will collect and throw error and warning messages. More...
 
void set_validate (bool val=true) noexcept
 By default, the parser will not validate the XML file. More...
 
- Public Member Functions inherited from xmlpp::NonCopyable
 NonCopyable (const NonCopyable &)=delete
 
 NonCopyable (NonCopyable &&)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
NonCopyableoperator= (NonCopyable &&)=delete
 

Protected Types

enum class  MsgType {
  ParserError ,
  ParserWarning ,
  ValidityError ,
  ValidityWarning
}
 

Protected Member Functions

virtual void check_for_error_and_warning_messages ()
 
virtual void check_for_exception ()
 
virtual void handle_exception ()
 To be called in an exception handler. More...
 
virtual void initialize_context ()
 
virtual void on_parser_error (const ustring & message)
 
virtual void on_parser_warning (const ustring & message)
 
virtual void on_validity_error (const ustring & message)
 
virtual void on_validity_warning (const ustring & message)
 
virtual void release_underlying ()
 
- Protected Member Functions inherited from xmlpp::NonCopyable
 NonCopyable () noexcept
 
virtual ~NonCopyable ()
 

Static Protected Member Functions

static void callback_error_or_warning (bool is_parser, bool is_error, void * ctx, const char * msg, va_list var_args)
 
static void callback_error_or_warning (MsgType msg_type, void * ctx, const char * msg, va_list var_args)
 
static void callback_parser_error (void * ctx, const char * msg,...)
 
static void callback_parser_warning (void * ctx, const char * msg,...)
 
static void callback_validity_error (void * ctx, const char * msg,...)
 
static void callback_validity_warning (void * ctx, const char * msg,...)
 
static ParserCallbackCFuncType get_callback_parser_error_cfunc ()
 
static ParserCallbackCFuncType get_callback_parser_warning_cfunc ()
 
static ParserCallbackCFuncType get_callback_validity_error_cfunc ()
 
static ParserCallbackCFuncType get_callback_validity_warning_cfunc ()
 

Protected Attributes

_xmlParserCtxt * context_
 
std::unique_ptr< exceptionexception_
 

Detailed Description

XML parser.

Abstract base class for DOM parser and SAX parser.

Member Typedef Documentation

◆ size_type

using xmlpp::Parser::size_type = unsigned int

Member Enumeration Documentation

◆ MsgType

enum xmlpp::Parser::MsgType
strongprotected
Deprecated:
Enumerator
ParserError 
ParserWarning 
ValidityError 
ValidityWarning 

Constructor & Destructor Documentation

◆ Parser()

xmlpp::Parser::Parser ( )

◆ ~Parser()

xmlpp::Parser::~Parser ( )
override

Member Function Documentation

◆ callback_error_or_warning() [1/2]

static void xmlpp::Parser::callback_error_or_warning ( bool  is_parser,
bool  is_error,
void *  ctx,
const char *  msg,
va_list  var_args 
)
staticprotected

◆ callback_error_or_warning() [2/2]

static void xmlpp::Parser::callback_error_or_warning ( MsgType  msg_type,
void *  ctx,
const char *  msg,
va_list  var_args 
)
staticprotected
Deprecated:
Use the other callback_error_or_warning() overload instead.

◆ callback_parser_error()

static void xmlpp::Parser::callback_parser_error ( void *  ctx,
const char *  msg,
  ... 
)
staticprotected

◆ callback_parser_warning()

static void xmlpp::Parser::callback_parser_warning ( void *  ctx,
const char *  msg,
  ... 
)
staticprotected

◆ callback_validity_error()

static void xmlpp::Parser::callback_validity_error ( void *  ctx,
const char *  msg,
  ... 
)
staticprotected

◆ callback_validity_warning()

static void xmlpp::Parser::callback_validity_warning ( void *  ctx,
const char *  msg,
  ... 
)
staticprotected

◆ check_for_error_and_warning_messages()

virtual void xmlpp::Parser::check_for_error_and_warning_messages ( )
protectedvirtual

◆ check_for_exception()

virtual void xmlpp::Parser::check_for_exception ( )
protectedvirtual

◆ get_callback_parser_error_cfunc()

static ParserCallbackCFuncType xmlpp::Parser::get_callback_parser_error_cfunc ( )
staticprotected

◆ get_callback_parser_warning_cfunc()

static ParserCallbackCFuncType xmlpp::Parser::get_callback_parser_warning_cfunc ( )
staticprotected

◆ get_callback_validity_error_cfunc()

static ParserCallbackCFuncType xmlpp::Parser::get_callback_validity_error_cfunc ( )
staticprotected

◆ get_callback_validity_warning_cfunc()

static ParserCallbackCFuncType xmlpp::Parser::get_callback_validity_warning_cfunc ( )
staticprotected

◆ get_include_default_attributes()

bool xmlpp::Parser::get_include_default_attributes ( ) const
noexcept

See set_include_default_attributes().

Since libxml++ 2.38:
Returns
Whether attributes with default values will be included in the node tree.

◆ get_parser_options()

void xmlpp::Parser::get_parser_options ( int &  set_options,
int &  clear_options 
) const
noexcept

See set_parser_options().

Since libxml++ 2.38:
Parameters
[out]set_optionsSet bits correspond to flags that shall be set during parsing.
[out]clear_optionsSet bits correspond to flags that shall be cleared during parsing. Bits that are set in neither set_options nor clear_options are not affected.

◆ get_substitute_entities()

bool xmlpp::Parser::get_substitute_entities ( ) const
noexcept

See set_substitute_entities().

Returns
Whether entities will be substituted during parsing.

◆ get_throw_messages()

bool xmlpp::Parser::get_throw_messages ( ) const
noexcept

See set_throw_messages().

Since libxml++ 2.36:
Returns
Whether messages will be collected and thrown in an exception.

◆ get_validate()

bool xmlpp::Parser::get_validate ( ) const
noexcept

See set_validate().

Returns
Whether the parser will validate the XML file.

◆ handle_exception()

virtual void xmlpp::Parser::handle_exception ( )
protectedvirtual

To be called in an exception handler.

◆ initialize_context()

virtual void xmlpp::Parser::initialize_context ( )
protectedvirtual

Reimplemented in xmlpp::SaxParser.

◆ on_parser_error()

virtual void xmlpp::Parser::on_parser_error ( const ustring message)
protectedvirtual

◆ on_parser_warning()

virtual void xmlpp::Parser::on_parser_warning ( const ustring message)
protectedvirtual

◆ on_validity_error()

virtual void xmlpp::Parser::on_validity_error ( const ustring message)
protectedvirtual

◆ on_validity_warning()

virtual void xmlpp::Parser::on_validity_warning ( const ustring message)
protectedvirtual

◆ parse_file()

virtual void xmlpp::Parser::parse_file ( const std::string filename)
pure virtual

Parse an XML document from a file.

Exceptions
exception
Parameters
filenameThe path to the file.

Implemented in xmlpp::SaxParser, and xmlpp::DomParser.

◆ parse_memory()

virtual void xmlpp::Parser::parse_memory ( const ustring contents)
pure virtual

Parse an XML document from a string.

Exceptions
exception
Parameters
contentsThe XML document as a string.

Implemented in xmlpp::SaxParser, and xmlpp::DomParser.

◆ parse_memory_raw()

virtual void xmlpp::Parser::parse_memory_raw ( const unsigned char *  contents,
size_type  bytes_count 
)
pure virtual

Parse an XML document from raw memory.

Exceptions
exception
Parameters
contentsThe XML document as an array of bytes.
bytes_countThe number of bytes in the contents array.

Implemented in xmlpp::SaxParser, and xmlpp::DomParser.

◆ parse_stream()

virtual void xmlpp::Parser::parse_stream ( std::istream in)
pure virtual

Parse an XML document from a stream.

Exceptions
exception
Parameters
inThe stream.

Implemented in xmlpp::SaxParser, and xmlpp::DomParser.

◆ release_underlying()

virtual void xmlpp::Parser::release_underlying ( )
protectedvirtual

Reimplemented in xmlpp::SaxParser, and xmlpp::DomParser.

◆ set_include_default_attributes()

void xmlpp::Parser::set_include_default_attributes ( bool  val = true)
noexcept

Set whether default attribute values from the DTD shall be included in the node tree.

If set, attributes not assigned a value in the XML file, but with a default value in the DTD file, will be included in the node tree that the parser creates. These attributes will be represented by AttributeNode instances (not AttributeDeclaration instances), just like attributes which are assigned a value in the XML file.

Since libxml++ 2.38:
Parameters
valWhether attributes with default values will be included in the node tree.

◆ set_parser_options()

void xmlpp::Parser::set_parser_options ( int  set_options = 0,
int  clear_options = 0 
)
noexcept

Set and/or clear parser option flags.

See the libxml2 documentation, enum xmlParserOption, for a list of parser options. This method overrides other methods that set parser options, such as set_validate(), set_substitute_entities() and set_include_default_attributes(). Use set_parser_options() only if no other method can set the parser options you want.

Since libxml++ 2.38:
Parameters
set_optionsSet bits correspond to flags that shall be set during parsing.
clear_optionsSet bits correspond to flags that shall be cleared during parsing. Bits that are set in neither set_options nor clear_options are not affected.

◆ set_substitute_entities()

void xmlpp::Parser::set_substitute_entities ( bool  val = true)
noexcept

Set whether the parser will automatically substitute entity references with the text of the entities' definitions.

For instance, this affects the text returned by ContentNode::get_content(). By default, the parser will not substitute entities, so that you do not lose the entity reference information.

Parameters
valWhether entities will be substitued.

◆ set_throw_messages()

void xmlpp::Parser::set_throw_messages ( bool  val = true)
noexcept

Set whether the parser will collect and throw error and warning messages.

If messages are collected, they are included in an exception thrown at the end of parsing.

  • DOM parser

    If the messages are not collected, they are written on stderr. The messages written on stderr are slightly different, and may be preferred in a program started from the command-line. The default, if set_throw_messages() is not called, is to collect and throw messages.

  • SAX parser

    If the messages are not collected, the error handling on_*() methods in the user's SAX parser subclass are called. This is the default, if set_throw_messages() is not called.

    Since libxml++ 2.36:
Parameters
valWhether messages will be collected and thrown in an exception.

◆ set_validate()

void xmlpp::Parser::set_validate ( bool  val = true)
noexcept

By default, the parser will not validate the XML file.

Parameters
valWhether the document should be validated.

Member Data Documentation

◆ context_

_xmlParserCtxt* xmlpp::Parser::context_
protected

◆ exception_

std::unique_ptr<exception> xmlpp::Parser::exception_
protected