libxml++: xmlpp::DomParser Class Reference

DOM XML parser. More...

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

Inheritance diagram for xmlpp::DomParser:

Public Member Functions

 DomParser ()
 Create a parser with an empty document. More...

 
 DomParser (const std::string& filename, bool validate=false)
 Instantiate the parser and parse a document immediately. More...

 
 ~DomParser () override
 
Documentget_document () noexcept
 Get the parsed document. More...

 
const Documentget_document () const noexcept
 Get the parsed document. More...

 
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. More...

 
 operator bool () const noexcept
 Test whether a document has been parsed. More...

 
void parse_file (const std::string& filename) override
 Parse an XML document from a file. More...

 
void parse_memory (const ustring& contents) override
 Parse an XML document from a string. More...

 
void parse_memory_raw (const unsigned char* contents, size_type bytes_count) override
 Parse an XML document from raw memory. More...

 
void parse_stream (std::istream& in) override
 Parse an XML document from a stream. More...

 
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. More...

 
- Public Member Functions inherited from xmlpp::Parser
 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...

 
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...

 

Protected Member Functions

void check_xinclude_and_finish_parsing ()
 
void parse_context ()
 
void release_underlying () override
 
- Protected Member Functions inherited from xmlpp::Parser
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)
 
- Protected Member Functions inherited from xmlpp::NonCopyable
 NonCopyable () noexcept
 
 NonCopyable (const NonCopyable&)=delete
 
 NonCopyable (NonCopyable&&)=delete
 
virtual ~NonCopyable ()
 
NonCopyableoperator= (const NonCopyable&)=delete
 
NonCopyableoperator= (NonCopyable&&)=delete
 

Protected Attributes

Documentdoc_
 
int xinclude_options_ = 0
 
- Protected Attributes inherited from xmlpp::Parser
_xmlParserCtxt* context_
 
std::unique_ptr< exceptionexception_
 

Additional Inherited Members

- Public Types inherited from xmlpp::Parser
using size_type = unsigned int
 
- Protected Types inherited from xmlpp::Parser
enum  MsgType {

  MsgType::ParserError,

  MsgType::ParserWarning,

  MsgType::ValidityError,

  MsgType::ValidityWarning

}
 
- 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.

DOM = Document Object Model

Constructor & Destructor Documentation

xmlpp::DomParser::DomParser ( )

Create a parser with an empty document.

Exceptions
xmlpp::internal_errorIf an empty document can't be created.
xmlpp::DomParser::DomParser ( const std::string filename,
bool  validate = false 
)
explicit

Instantiate the parser and parse a document immediately.

Parameters
filenameThe path to the file.
validateWhether the parser should validate the XML.
Exceptions
xmlpp::internal_error
xmlpp::parse_error
xmlpp::validity_error
xmlpp::DomParser::~DomParser ( )
override

Member Function Documentation

void xmlpp::DomParser::check_xinclude_and_finish_parsing ( )
protected
Document* xmlpp::DomParser::get_document ( )
noexcept

Get the parsed document.

Returns
A pointer to the parsed document, or nullptr.
const Document* xmlpp::DomParser::get_document ( ) const
noexcept

Get the parsed document.

Returns
A pointer to the parsed document, or nullptr.
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++ 3.2:
Parameters
[out]process_xincludeDo XInclude substitution on the XML document.
[out]generate_xinclude_nodesGenerate XIncludeStart and XIncludeEnd nodes.
[out]fixup_base_urisAdd or replace xml:base attributes in included element nodes, if necessary to preserve the target of relative URIs.
xmlpp::DomParser::operator bool ( ) const
explicitnoexcept

Test whether a document has been parsed.

void xmlpp::DomParser::parse_context ( )
protected
void xmlpp::DomParser::parse_file ( const std::string 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
filenameThe path to the file.
Exceptions
xmlpp::internal_error
xmlpp::parse_error
xmlpp::validity_error

Implements xmlpp::Parser.

void xmlpp::DomParser::parse_memory ( const 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
contentsThe XML document as a string.
Exceptions
xmlpp::internal_error
xmlpp::parse_error
xmlpp::validity_error

Implements xmlpp::Parser.

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

Parse an XML document from raw memory.

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

Parameters
contentsThe XML document as an array of bytes.
bytes_countThe number of bytes in the contents array.
Exceptions
xmlpp::internal_error
xmlpp::parse_error
xmlpp::validity_error

Implements xmlpp::Parser.

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
inThe stream.
Exceptions
xmlpp::internal_error
xmlpp::parse_error
xmlpp::validity_error

Implements xmlpp::Parser.

void xmlpp::DomParser::release_underlying ( )
overrideprotectedvirtual

Reimplemented from xmlpp::Parser.

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++ 3.2:
Parameters
process_xincludeDo XInclude substitution on the XML document. If false, the other parameters have no effect.
generate_xinclude_nodesGenerate XIncludeStart and XIncludeEnd nodes.
fixup_base_urisAdd or replace xml:base attributes in included element nodes, if necessary to preserve the target of relative URIs.

Member Data Documentation

Document* xmlpp::DomParser::doc_
protected
int xmlpp::DomParser::xinclude_options_ = 0
protected