libxml++: xmlpp::Parser Class Reference

libxml++ 2.42.1

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:
[legend]

## Public Types
typedef unsigned int | size_type

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

## Protected Types
enum | MsgType { MsgParserError , MsgParserWarning , MsgValidityError , MsgValidityWarning }

## Protected Member Functions
virtual LIBXMLPP_API void | check_for_exception ()
virtual LIBXMLPP_API void | check_for_validity_messages ()
LIBXMLPP_API int | get_xinclude_options_internal () const noexcept
virtual LIBXMLPP_API void | handleException (const exception& e)
virtual LIBXMLPP_API void | initialize_context ()
virtual LIBXMLPP_API void | on_validity_error (const Glib::ustring& message)
virtual LIBXMLPP_API void | on_validity_warning (const Glib::ustring& message)
virtual LIBXMLPP_API void | release_underlying ()
LIBXMLPP_API void | set_xinclude_options_internal (int xinclude_options) noexcept

## Static Protected Member Functions
static LIBXMLPP_API void | callback_error_or_warning (MsgType msg_type, void* ctx, const char* msg, va_list var_args)
static LIBXMLPP_API void | callback_parser_error (void* ctx, const char* msg,...)
static LIBXMLPP_API void | callback_parser_warning (void* ctx, const char* msg,...)
static LIBXMLPP_API void | callback_validity_error (void* ctx, const char* msg,...)
static LIBXMLPP_API void | callback_validity_warning (void* ctx, const char* msg,...)

## Protected Attributes
_xmlParserCtxt* | context_
exception* | exception_
bool | substitute_entities_
bool | validate_
Glib::ustring | validate_error_
Glib::ustring | validate_warning_

## Detailed Description

XML parser.

## Member Typedef Documentation

## ◆ size_type

typedef unsigned int xmlpp::Parser::size_type

## Member Enumeration Documentation

## ◆ MsgType

enum xmlpp::Parser::MsgType
| protected

Enumerator
MsgParserError |
MsgParserWarning |
MsgValidityError |
MsgValidityWarning |

## Constructor & Destructor Documentation

## ◆ Parser()

LIBXMLPP_API xmlpp::Parser::Parser | ( |  | ) |

## ◆ ~Parser()

LIBXMLPP_API xmlpp::Parser::~Parser | ( |  | ) |
| override

## Member Function Documentation

## ◆ callback_error_or_warning()

static LIBXMLPP_API void xmlpp::Parser::callback_error_or_warning | ( | MsgType | msg_type,
|  | void * | ctx,
|  | const char * | msg,
|  | va_list | var_args
| ) |  |
| staticprotected

## ◆ callback_parser_error()

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

## ◆ callback_parser_warning()

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

## ◆ callback_validity_error()

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

## ◆ callback_validity_warning()

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

## ◆ check_for_exception()

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

## ◆ check_for_validity_messages()

virtual LIBXMLPP_API void xmlpp::Parser::check_for_validity_messages | ( |  | ) |
| protectedvirtual

## ◆ get_include_default_attributes()

LIBXMLPP_API bool xmlpp::Parser::get_include_default_attributes | ( |  | ) |

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()

LIBXMLPP_API void xmlpp::Parser::get_parser_options | ( | int & | set_options,
|  | int & | clear_options
| ) |  |

See set_parser_options().

Since libxml++ 2.38:

Parameters

  [out] | set_options | Set bits correspond to flags that shall be set during parsing.
  [out] | clear_options | Set 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()

virtual LIBXMLPP_API bool xmlpp::Parser::get_substitute_entities | ( |  | ) | const
| virtual

See set_substitute_entities().

Returns
  Whether entities will be substituted during parsing.

## ◆ get_throw_messages()

LIBXMLPP_API bool xmlpp::Parser::get_throw_messages | ( |  | ) | const

See set_throw_messages().

Since libxml++ 2.36:

Returns
  Whether messages will be collected and thrown in an exception. The default with only validation messages thrown is returned as false.

## ◆ get_validate()

virtual LIBXMLPP_API bool xmlpp::Parser::get_validate | ( |  | ) | const
| virtual

See set_validate().

Returns
  Whether the parser will validate the XML file.

## ◆ get_xinclude_options_internal()

LIBXMLPP_API int xmlpp::Parser::get_xinclude_options_internal | ( |  | ) | const
| protectednoexcept

## ◆ handleException()

virtual LIBXMLPP_API void xmlpp::Parser::handleException | ( | const exception& | e | ) |
| protectedvirtual

## ◆ initialize_context()

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

## ◆ on_validity_error()

virtual LIBXMLPP_API void xmlpp::Parser::on_validity_error | ( | const Glib::ustring & | message | ) |
| protectedvirtual

## ◆ on_validity_warning()

virtual LIBXMLPP_API void xmlpp::Parser::on_validity_warning | ( | const Glib::ustring & | message | ) |
| protectedvirtual

## ◆ parse_file()

virtual LIBXMLPP_API void xmlpp::Parser::parse_file | ( | const Glib::ustring & | filename | ) |
| pure virtual

Parse an XML document from a file.

Exceptions

  exception |

Parameters

  filename | The path to the file.

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

## ◆ parse_memory()

virtual LIBXMLPP_API void xmlpp::Parser::parse_memory | ( | const Glib::ustring & | contents | ) |
| pure virtual

Parse an XML document from a string.

Exceptions

  exception |

Parameters

  contents | The XML document as a string.

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

## ◆ parse_stream()

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

Parse an XML document from a stream.

Exceptions

  exception |

Parameters

  in | The stream.

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

## ◆ release_underlying()

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

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

## ◆ set_include_default_attributes()

LIBXMLPP_API void xmlpp::Parser::set_include_default_attributes | ( | bool | val = `true` | ) |

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

  val | Whether attributes with default values will be included in the node tree.

## ◆ set_parser_options()

LIBXMLPP_API void xmlpp::Parser::set_parser_options | ( | int | set_options = `0`,
|  | int | clear_options = `0`
| ) |  |

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_options | Set bits correspond to flags that shall be set during parsing.
  clear_options | Set 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()

virtual LIBXMLPP_API void xmlpp::Parser::set_substitute_entities | ( | bool | val = `true` | ) |
| virtual

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

  val | Whether entities will be substitued.

## ◆ set_throw_messages()

LIBXMLPP_API void xmlpp::Parser::set_throw_messages | ( | bool | val = `true` | ) |

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. 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 only messages from validation. Other messages are written to stderr. This is for backward compatibility, and may change in the future.

Since libxml++ 2.36:

Parameters

  val | Whether messages will be collected and thrown in an exception.

## ◆ set_validate()

virtual LIBXMLPP_API void xmlpp::Parser::set_validate | ( | bool | val = `true` | ) |
| virtual

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

Parameters

  val | Whether the document should be validated.

## ◆ set_xinclude_options_internal()

LIBXMLPP_API void xmlpp::Parser::set_xinclude_options_internal | ( | int | xinclude_options | ) |
| protectednoexcept

## Member Data Documentation

## ◆ context_

_xmlParserCtxt* xmlpp::Parser::context_
| protected

## ◆ exception_

exception* xmlpp::Parser::exception_
| protected

## ◆ substitute_entities_

bool xmlpp::Parser::substitute_entities_
| protected

## ◆ validate_

bool xmlpp::Parser::validate_
| protected

## ◆ validate_error_

Glib::ustring xmlpp::Parser::validate_error_
| protected

## ◆ validate_warning_

Glib::ustring xmlpp::Parser::validate_warning_
| protected