libxml++: xmlpp::DomParser Class Reference

libxml++ 2.42.4

Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
xmlpp::DomParser Class Reference

DOM XML parser. More...

`#include <libxml++/parsers/domparser.h>`

Inheritance diagram for xmlpp::DomParser:
[legend]

## Public Member Functions
| DomParser ()
| Create a parser with an empty document.
| DomParser (const Glib::ustring & filename, bool validate=false)
| Instantiate the parser and parse a document immediately.
| ~DomParser () override
Document * | get_document ()
| Get the parsed document.
const Document * | get_document () const
| Get the parsed document.
void | get_xinclude_options (bool & process_xinclude, bool & generate_xinclude_nodes, bool & fixup_base_uris) const noexcept
| Get whether and how the parser will perform XInclude substitution.
| operator bool () const
| Test whether a document has been parsed.
void | parse_file (const Glib::ustring & filename) override
| Parse an XML document from a file.
void | parse_memory (const Glib::ustring & contents) override
| Parse an XML document from a string.
void | parse_memory_raw (const unsigned char * contents, size_type bytes_count)
| Parse an XML document from raw memory.
void | parse_stream (std::istream & in) override
| Parse an XML document from a stream.
void | set_xinclude_options (bool process_xinclude=true, bool generate_xinclude_nodes=true, bool fixup_base_uris=true) noexcept
| Set whether and how the parser will perform XInclude substitution.
Public Member Functions inherited from xmlpp::Parser
| Parser ()
| ~Parser () override
bool | get_include_default_attributes ()
| See set_include_default_attributes().
void | get_parser_options (int & set_options, int & clear_options)
| See set_parser_options().
virtual bool | get_substitute_entities () const
| See set_substitute_entities().
bool | get_throw_messages () const
| See set_throw_messages().
virtual bool | get_validate () const
| See set_validate().
void | set_include_default_attributes (bool val=true)
| Set whether default attribute values from the DTD shall be included in the node tree.
void | set_parser_options (int set_options=0, int clear_options=0)
| Set and/or clear parser option flags.
virtual void | set_substitute_entities (bool val=true)
| Set whether the parser will automatically substitute entity references with the text of the entities' definitions.
void | set_throw_messages (bool val=true)
| Set whether the parser will collect and throw error and warning messages.
virtual void | set_validate (bool val=true)
| By default, the parser will not validate the XML file.

## Protected Member Functions
void | check_xinclude_and_finish_parsing ()
virtual void | parse_context ()
void | release_underlying () override
Protected Member Functions inherited from xmlpp::Parser
virtual void | check_for_exception ()
virtual void | check_for_validity_messages ()
int | get_xinclude_options_internal () const noexcept
virtual void | handleException (const exception & e)
virtual void | initialize_context ()
virtual void | on_validity_error (const Glib::ustring & message)
virtual void | on_validity_warning (const Glib::ustring & message)
void | set_xinclude_options_internal (int xinclude_options) noexcept

## Protected Attributes
Document * | doc_
Protected Attributes inherited from xmlpp::Parser
_xmlParserCtxt * | context_
exception * | exception_
bool | substitute_entities_
bool | validate_
Glib::ustring | validate_error_
Glib::ustring | validate_warning_

## Additional Inherited Members
Public Types inherited from xmlpp::Parser
typedef unsigned int | size_type
Protected Types inherited from xmlpp::Parser
enum | MsgType { MsgParserError , MsgParserWarning , MsgValidityError , MsgValidityWarning }
Static Protected Member Functions inherited from xmlpp::Parser
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,...)

## Detailed Description

DOM XML parser.

## Constructor & Destructor Documentation

## ◆ DomParser() [1/2]

xmlpp::DomParser::DomParser | ( |  | ) |

Create a parser with an empty document.

Exceptions

  xmlpp::internal_error | If an empty document can't be created.

## ◆ DomParser() [2/2]

xmlpp::DomParser::DomParser | ( | const Glib::ustring & | filename,
|  | bool | validate = false )
| explicit

Instantiate the parser and parse a document immediately.

Parameters

  filename | The path to the file.
  validate | Whether the parser should validate the XML.

Exceptions

  xmlpp::internal_error |
  xmlpp::parse_error |
  xmlpp::validity_error |

## ◆ ~DomParser()

xmlpp::DomParser::~DomParser | ( |  | ) |
| override

## Member Function Documentation

## ◆ check_xinclude_and_finish_parsing()

void xmlpp::DomParser::check_xinclude_and_finish_parsing | ( |  | ) |
| protected

## ◆ get_document() [1/2]

Document * xmlpp::DomParser::get_document | ( |  | ) |

Get the parsed document.

Returns
  A pointer to the parsed document, or nullptr.

## ◆ get_document() [2/2]

const Document * xmlpp::DomParser::get_document | ( |  | ) | const

Get the parsed document.

Returns
  A pointer to the parsed document, or nullptr.

## ◆ get_xinclude_options()

void xmlpp::DomParser::get_xinclude_options | ( | bool & | process_xinclude,
|  | bool & | generate_xinclude_nodes,
|  | bool & | fixup_base_uris ) const
| noexcept

Get whether and how the parser will perform XInclude substitution.

Since libxml++ 2.42

Parameters

  [out] | process_xinclude | Do XInclude substitution on the XML document.
  [out] | generate_xinclude_nodes | Generate XIncludeStart and XIncludeEnd nodes.
  [out] | fixup_base_uris | Add or replace xml:base attributes in included element nodes, if necessary to preserve the target of relative URIs.

## ◆ operator bool()

xmlpp::DomParser::operator bool | ( |  | ) | const

Test whether a document has been parsed.

## ◆ parse_context()

virtual void xmlpp::DomParser::parse_context | ( |  | ) |
| protectedvirtual

## ◆ parse_file()

void xmlpp::DomParser::parse_file | ( | const Glib::ustring & | filename | ) |
| overridevirtual

Parse an XML document from a file.

If the parser already contains a document, that document and all its nodes are deleted.

Parameters

  filename | The path to the file.

Exceptions

  xmlpp::internal_error |
  xmlpp::parse_error |
  xmlpp::validity_error |

Implements xmlpp::Parser.

## ◆ parse_memory()

void xmlpp::DomParser::parse_memory | ( | const Glib::ustring & | contents | ) |
| overridevirtual

Parse an XML document from a string.

If the parser already contains a document, that document and all its nodes are deleted.

Parameters

  contents | The XML document as a string.

Exceptions

  xmlpp::internal_error |
  xmlpp::parse_error |
  xmlpp::validity_error |

Implements xmlpp::Parser.

## ◆ parse_memory_raw()

void xmlpp::DomParser::parse_memory_raw | ( | const unsigned char * | contents,
|  | size_type | bytes_count )

Parse an XML document from raw memory.

If the parser already contains a document, that document and all its nodes are deleted.

Parameters

  contents | The XML document as an array of bytes.
  bytes_count | The number of bytes in the contents array.

Exceptions

  xmlpp::internal_error |
  xmlpp::parse_error |
  xmlpp::validity_error |

## ◆ parse_stream()

void xmlpp::DomParser::parse_stream | ( | std::istream & | in | ) |
| overridevirtual

Parse an XML document from a stream.

If the parser already contains a document, that document and all its nodes are deleted.

Parameters

  in | The stream.

Exceptions

  xmlpp::internal_error |
  xmlpp::parse_error |
  xmlpp::validity_error |

Implements xmlpp::Parser.

## ◆ release_underlying()

void xmlpp::DomParser::release_underlying | ( |  | ) |
| overrideprotectedvirtual

Reimplemented from xmlpp::Parser.

## ◆ set_xinclude_options()

void xmlpp::DomParser::set_xinclude_options | ( | bool | process_xinclude = true,
|  | bool | generate_xinclude_nodes = true,
|  | bool | fixup_base_uris = true )
| noexcept

Set whether and how the parser will perform XInclude substitution.

Since libxml++ 2.42

Parameters

  process_xinclude | Do XInclude substitution on the XML document. If false, the other parameters have no effect.
  generate_xinclude_nodes | Generate XIncludeStart and XIncludeEnd nodes.
  fixup_base_uris | Add or replace xml:base attributes in included element nodes, if necessary to preserve the target of relative URIs.

## Member Data Documentation

## ◆ doc_

Document* xmlpp::DomParser::doc_
| protected