xmlwrapp
Lightweight C++ XML parsing library
Public Member Functions | List of all members
xml::tree_parser Class Reference

The xml::tree_parser class is used to parse an XML document and generate a tree like structure of xml::node objects. More...

#include <tree_parser.h>

Public Member Functions

 tree_parser (const char *filename, error_handler &on_error=throw_on_error)
 xml::tree_parser class constructor. More...
 
 tree_parser (const char *data, size_type size, error_handler &on_error=throw_on_error)
 xml::tree_parser class constructor. More...
 
 tree_parser (const char *filename, bool allow_exceptions)
 xml::tree_parser class constructor. More...
 
 tree_parser (const char *data, size_type size, bool allow_exceptions)
 xml::tree_parser class constructor. More...
 
const error_messagesmessages () const
 Return error_messages object with errors and warnings collected during parsing. More...
 
bool operator! () const
 Check to see if a xml::tree_parser class is valid. More...
 
const std::string & get_error_message () const
 If operator! indicates that there was an error parsing your XML data, you can use this member function to get the error message that was generated during parsing. More...
 
bool had_warnings () const
 Check to see if there were any warnings from the parser while processing the given XML data. More...
 
xml::documentget_document ()
 Get a reference to the xml::document that was generated during the XML parsing. More...
 
const xml::documentget_document () const
 Get a const reference to the xml::document that was generate during the XML parsing. More...
 

Detailed Description

The xml::tree_parser class is used to parse an XML document and generate a tree like structure of xml::node objects.

After constructing a tree_parser, with either a file to parse or some in memory data to parse, you can walk the tree using the xml::node interface.

Note
You probably don't need to use this class directly anymore and can just use the corresponding xml::document constructors.

Constructor & Destructor Documentation

◆ tree_parser() [1/4]

xml::tree_parser::tree_parser ( const char *  filename,
error_handler on_error = throw_on_error 
)

xml::tree_parser class constructor.

Given the name of a file, this constructor will parse that file.

Parameters
filenameThe name of the file to parse.
on_errorHandler called to process errors and warnings.
Since
0.7.0

◆ tree_parser() [2/4]

xml::tree_parser::tree_parser ( const char *  data,
size_type  size,
error_handler on_error = throw_on_error 
)

xml::tree_parser class constructor.

Given some data and the size of that data, parse that data as XML.

Parameters
dataThe XML data to parse.
sizeThe size of the XML data to parse.
on_errorHandler called to process errors and warnings.
Since
0.7.0

◆ tree_parser() [3/4]

xml::tree_parser::tree_parser ( const char *  filename,
bool  allow_exceptions 
)

xml::tree_parser class constructor.

Given the name of a file, this constructor will parse that file.

There are two options for dealing with XML parsing errors. The default it to throw an exception (xml::exception). The other option is to pass false for the allow_exceptions flag. This will prevent an exception from being thrown, instead, a flag will be set that you can test with the operator! member function.

No matter what option you choose, this constructor may still throw exceptions for memory failure or other non-parsing related failures.

Parameters
filenameThe name of the file to parse.
allow_exceptionsWhether or not you want an exception for parsing errors.

◆ tree_parser() [4/4]

xml::tree_parser::tree_parser ( const char *  data,
size_type  size,
bool  allow_exceptions 
)

xml::tree_parser class constructor.

Given some data and the size of that data, parse that data as XML. To see if the data was parsed successfully use operator!.

Parameters
dataThe XML data to parse.
sizeThe size of the XML data to parse.
allow_exceptionsWhether or not you want an exception for parsing errors.

Member Function Documentation

◆ get_document() [1/2]

xml::document& xml::tree_parser::get_document ( )

Get a reference to the xml::document that was generated during the XML parsing.

You should make sure to only use a reference to the document to avoid a deep copy.

Returns
A reference to the xml::document.

◆ get_document() [2/2]

const xml::document& xml::tree_parser::get_document ( ) const

Get a const reference to the xml::document that was generate during the XML parsing.

You should make sure to only use a reference to the document to avoid a deep copy.

Returns
A const reference to the xml::document.

◆ get_error_message()

const std::string& xml::tree_parser::get_error_message ( ) const

If operator! indicates that there was an error parsing your XML data, you can use this member function to get the error message that was generated during parsing.

Returns
The error message generated during XML parsing.
Deprecated:
Use messages() instead.

◆ had_warnings()

bool xml::tree_parser::had_warnings ( ) const

Check to see if there were any warnings from the parser while processing the given XML data.

If there were, you may want to send the same document through xmllint or the event_parser to catch and review the warning messages.

Returns
True if there were any warnings.
False if there were no warnings.

◆ messages()

const error_messages& xml::tree_parser::messages ( ) const

Return error_messages object with errors and warnings collected during parsing.

Since
0.7.0

◆ operator!()

bool xml::tree_parser::operator! ( ) const

Check to see if a xml::tree_parser class is valid.

That is, check to see if parsing XML data was successful and the tree_parser holds a good XML node tree.

Returns
True if the tree_parser is NOT VALID; false if it is valid.

The documentation for this class was generated from the following file: