xmlwrapp
Lightweight C++ XML parsing library
|
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_messages & | messages () 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::document & | get_document () |
Get a reference to the xml::document that was generated during the XML parsing. More... | |
const xml::document & | get_document () const |
Get a const reference to the xml::document that was generate during the XML parsing. More... | |
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.
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.
filename | The name of the file to parse. |
on_error | Handler called to process errors and warnings. |
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.
data | The XML data to parse. |
size | The size of the XML data to parse. |
on_error | Handler called to process errors and warnings. |
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.
filename | The name of the file to parse. |
allow_exceptions | Whether or not you want an exception for parsing errors. |
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!.
data | The XML data to parse. |
size | The size of the XML data to parse. |
allow_exceptions | Whether or not you want an exception for parsing errors. |
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.
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.
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.
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.
const error_messages& xml::tree_parser::messages | ( | ) | const |
Return error_messages object with errors and warnings collected during parsing.
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.