MLBookProc 1.3
Loading...
Searching...
No Matches
XMLParser Class Reference

The XMLParser class. More...

#include <XMLParser.h>

Inheritance diagram for XMLParser:

Public Member Functions

 XMLParser (const std::shared_ptr< AuxFunc > &af)
 XMLParser constructor.
std::vector< XMLTagget_tag (const std::string &book, const std::string &tag_id)
 Returns all tags with particular name.
std::string get_book_encoding (const std::string &book)
 Returns XML document encoding.
std::string get_element_attribute (const std::string &element, const std::string &attr_name)
 Returns XML tag attribute if it was found.
std::vector< XMLTaglistAllTags (const std::string &book)
 Parses XML document.
void searchTag (const std::vector< XMLTag > &list, const std::string &tag_id, std::vector< XMLTag > &result)
 Searches tag in tag list.
void htmlSymbolsReplacement (std::string &book)
 Replaces symbols encoded by "&..." sequences.
void removeAllTags (std::string &book)
 Removes all tag elements from XML document.

Detailed Description

The XMLParser class.

This class contains various methods to process XML documents.

Deprecated
This class will be removed in future releases. Use XMLParserCPP library instead.

Constructor & Destructor Documentation

◆ XMLParser()

XMLParser::XMLParser ( const std::shared_ptr< AuxFunc > & af)

XMLParser constructor.

Parameters
afsmart pointer to AuxFunc constructor.

Member Function Documentation

◆ get_book_encoding()

std::string XMLParser::get_book_encoding ( const std::string & book)

Returns XML document encoding.

Tries to get XML document header and read encoding from it.

Parameters
bookXML document content.
Returns
Returns XML document encoding if it was found.

◆ get_element_attribute()

std::string XMLParser::get_element_attribute ( const std::string & element,
const std::string & attr_name )

Returns XML tag attribute if it was found.

Parameters
elementtag start element (see XMLTag::element).
attr_namerequested attribute name.
Returns
Returns attribute content if it was found.

◆ get_tag()

std::vector< XMLTag > XMLParser::get_tag ( const std::string & book,
const std::string & tag_id )

Returns all tags with particular name.

This method uses listAllTags() and searchTag() under hood.

Note
This method can throw MLException in case of errors.
Parameters
bookXML document content.
tag_idrequested tag name.
Returns
Vector of found tags.

◆ htmlSymbolsReplacement()

void XMLParser::htmlSymbolsReplacement ( std::string & book)

Replaces symbols encoded by "&..." sequences.

Replaces symbols encoded by "&..." sequences for actual values (see this for details).

Parameters
bookXML document content symbols to be replaced in.

◆ listAllTags()

std::vector< XMLTag > XMLParser::listAllTags ( const std::string & book)

Parses XML document.

Returns all found tags.

Note
This method can throw MLException in case of errors.
Parameters
bookXML document content.
Returns
Vector of found tags.

◆ removeAllTags()

void XMLParser::removeAllTags ( std::string & book)

Removes all tag elements from XML document.

Simply removes all found XML tag elements and leaves only document content.

Parameters
bookXML document content.

◆ searchTag()

void XMLParser::searchTag ( const std::vector< XMLTag > & list,
const std::string & tag_id,
std::vector< XMLTag > & result )

Searches tag in tag list.

Searches tags in tag list by given tag name.

Parameters
listtag list search to be carried out in.
tag_idtag name for tags to be searched.
resultvector for results (can be not empty, this methods appends found tags to existing results).