libxcks  0.1.0.1
libxcks::XMLParser Class Reference

A very simple XML parser. More...

#include <xmlparser.hpp>

Inheritance diagram for libxcks::XMLParser:

Public Member Functions

bool parse (const std::string &filename)
 Parses the given file. More...
 
bool parse (std::istream &is)
 Parses the given input stream. More...
 

Protected Member Functions

 XMLParser ()
 Default constructor. More...
 
virtual ~XMLParser ()
 Destructor. More...
 
bool initParser ()
 Initializes the parser for parsing a new document. More...
 
virtual void startElement (const std::string &name, const XMLParserAttributes &atts) noexcept(false)
 Receives notification of the beginning of an element. More...
 
virtual void endElement (const std::string &name) noexcept(false)
 Receives notification of the end of an element. More...
 
virtual void characters (const std::string &chars) noexcept(false)
 Receives notification of character data. More...
 
virtual void fatalError (XML_Error errorCode, const std::string &errorMessage, int line, int column) noexcept
 Receive notification of a non-recoverable error. More...
 
int getDepth () const
 Returns the current depth in XML tree structure. More...
 

Detailed Description

A very simple XML parser.

Uses expat to parse XML streams. expat must be configured to use UTF-8 multi-bytes strings.

All the parsing methods must call initParser before parse a new document.

Definition at line 137 of file xmlparser.hpp.

Constructor & Destructor Documentation

◆ XMLParser()

libxcks::XMLParser::XMLParser ( )
protected

Default constructor.

Definition at line 333 of file xmlparser.cpp.

◆ ~XMLParser()

libxcks::XMLParser::~XMLParser ( )
protectedvirtual

Destructor.

Definition at line 343 of file xmlparser.cpp.

Member Function Documentation

◆ characters()

void libxcks::XMLParser::characters ( const std::string &  chars)
protectedvirtualnoexcept

Receives notification of character data.

This default implementation does nothing.

Parameters
charsThe characters from the XML document.

Reimplemented in libxcks::XCKSFileReader.

Definition at line 420 of file xmlparser.cpp.

◆ endElement()

void libxcks::XMLParser::endElement ( const std::string &  name)
protectedvirtualnoexcept

Receives notification of the end of an element.

This default implementation does nothing.

Parameters
nameThe name of the element.

Reimplemented in libxcks::XCKSFileReader.

Definition at line 407 of file xmlparser.cpp.

◆ fatalError()

void libxcks::XMLParser::fatalError ( XML_Error  errorCode,
const std::string &  errorMessage,
int  line,
int  column 
)
protectedvirtualnoexcept

Receive notification of a non-recoverable error.

This default implementation does nothing.

Parameters
errorCodeThe error code.
errorMessageThe error message.
lineThe line number the text where the error has occurred.
columnThe column number where the error has occurred.

Reimplemented in libxcks::XCKSFileReader.

Definition at line 436 of file xmlparser.cpp.

◆ getDepth()

int libxcks::XMLParser::getDepth ( ) const
protected

Returns the current depth in XML tree structure.

Returns
the current depth in XML tree structure.

Definition at line 530 of file xmlparser.cpp.

◆ initParser()

bool libxcks::XMLParser::initParser ( )
protected

Initializes the parser for parsing a new document.

Initializes also the current depth in the XML tree to 0.

This method must call before parsing any new document.

If a previous parser exists, it is erased before creating a new one.

If this method returns false the parser shouldn't begin to parse the document.

Returns
true if a new parser has been created, false otherwise.

Definition at line 366 of file xmlparser.cpp.

◆ parse() [1/2]

bool libxcks::XMLParser::parse ( const std::string &  filename)

Parses the given file.

Parameters
filenameThe name of the file to parse.
Returns
true if the file has been parsed successfully (with no errors), false otherwise.

Definition at line 544 of file xmlparser.cpp.

◆ parse() [2/2]

bool libxcks::XMLParser::parse ( std::istream &  is)

Parses the given input stream.

The stream is parsed until its end is reached or until an error occurs.

Parameters
isThe input stream to parse.
Returns
true if the file has been parsed successfully (with no errors), false otherwise.

Definition at line 561 of file xmlparser.cpp.

◆ startElement()

void libxcks::XMLParser::startElement ( const std::string &  name,
const XMLParserAttributes atts 
)
protectedvirtualnoexcept

Receives notification of the beginning of an element.

This default implementation does nothing.

Parameters
nameThe name of the element.
attsThe attributes attached to the element.

Reimplemented in libxcks::XCKSFileReader.

Definition at line 394 of file xmlparser.cpp.


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