Skip to main content

The XMLParser Class Reference

Declaration

class XMLParser { ... }

Included Headers

#include <libxml/xml.h>

Base class

classXMLLocator

Public Member Typedefs Index

usingTranscode = bool(std::string &, const char *)

Public Constructors Index

XMLParser (const XMLHandlers &handlers)
XMLParser (const XMLParser &)=delete
XMLParser (XMLParser &&)=delete

Public Destructor Index

~XMLParser () override

Public Operators Index

XMLParser &operator= (const XMLParser &)=delete
XMLParser &operator= (XMLParser &&)=delete

Public Member Functions Index

voidparse (const char *fileName, const char *inputString, bool debugEnabled, std::function< void()> debugStart, std::function< void()> debugEnd, std::function< Transcode > transcoder=[](std::string &s, const char *){ return true;})

Private Member Functions Index

intlineNr () const override
std::stringfileName () const override

Private Member Attributes Index

std::unique_ptr< Private >p

Description

Very basic SAX style parser to parse XML documents.

Definition at line 70 of file xml.h.

Public Member Typedefs

Transcode

using XMLParser::Transcode = bool(std::string &,const char *)

Definition at line 86 of file xml.h.

86 using Transcode = bool(std::string &,const char *);

Public Constructors

XMLParser()

XMLParser::XMLParser (const XMLHandlers & handlers)

Creates an instance of the parser object. Different instances can run on different threads without interference.

Parameters
handlers

The event handlers passed by the client.

Declaration at line 78 of file xml.h, definition at line 436 of file xml.l.

437{
438 xmlYYlex_init_extra(&p->xmlYY_extra,&p->yyscanner);
439 p->xmlYY_extra.handlers = handlers;
440}

Reference p.

Referenced by operator=, operator=, XMLParser and XMLParser.

XMLParser()

XMLParser::XMLParser (const XMLParser &)
delete

Definition at line 81 of file xml.h.

Reference XMLParser.

XMLParser()

XMLParser::XMLParser (XMLParser &&)
delete

Definition at line 83 of file xml.h.

Reference XMLParser.

Public Destructor

~XMLParser()

XMLParser::~XMLParser ()

Destructor

Declaration at line 80 of file xml.h, definition at line 442 of file xml.l.

443{
444 xmlYYlex_destroy(p->yyscanner);
445}

Reference p.

Public Operators

operator=()

XMLParser & XMLParser::operator= (const XMLParser &)
delete

Definition at line 82 of file xml.h.

Reference XMLParser.

operator=()

XMLParser & XMLParser::operator= (XMLParser &&)
delete

Definition at line 84 of file xml.h.

Reference XMLParser.

Public Member Functions

parse()

void XMLParser::parse (const char * fileName, const char * inputString, bool debugEnabled, std::function< void()> debugStart, std::function< void()> debugEnd, std::function< Transcode > transcoder=[](std::string &s, const char *){ return true;})

Parses a file gives the contents of the file as a string.

Parameters
fileName

the name of the file, used for error reporting.

inputString

the contents of the file as a zero terminated UTF-8 string.

debugEnabled

indicates if debugging via -d lex is enabled or not.

debugStart

hook that is to be called before starting with parsing

debugEnd

hook that is to be called after finishing with parsing

transcoder

hook that is to be called when transcoding text to UTF-8

Declaration at line 96 of file xml.h, definition at line 447 of file xml.l.

447void XMLParser::parse(const char *fileName,
448 const char *inputStr,
449 bool debugEnabled,
450 std::function<void()> debugStart,
451 std::function<void()> debugEnd,
452 std::function<Transcode> transcodeFunc)
453{
454 yyscan_t yyscanner = p->yyscanner;
455 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
456
457#ifdef FLEX_DEBUG
458 xmlYYset_debug(debugEnabled?1:0,p->yyscanner);
459#endif
460
461 if (inputStr==nullptr || inputStr[0]=='\0') return; // empty input
462
463 debugStart();
464
465 BEGIN(Initial);
466 yyextra->fileName = fileName;
467 yyextra->lineNr = 1;
468 yyextra->inputString = inputStr;
469 yyextra->inputPosition = 0;
470 yyextra->transcodeFunc = transcodeFunc;
471
472 if (static_cast<unsigned char>(inputStr[0])==0xEF &&
473 static_cast<unsigned char>(inputStr[1])==0xBB &&
474 static_cast<unsigned char>(inputStr[2])==0xBF)
475 {
476 yyextra->inputPosition = 3; // remove UTF-8 BOM
477 }
478
479 xmlYYrestart( 0, yyscanner );
480
481 if (yyextra->handlers.startDocument)
482 {
483 yyextra->handlers.startDocument();
484 }
485 xmlYYlex(yyscanner);
486 if (yyextra->handlers.endDocument)
487 {
488 yyextra->handlers.endDocument();
489 }
490
491 if (!yyextra->xpath.empty())
492 {
493 std::string tagName = yyextra->xpath.back();
494 std::string msg = "End of file reached while expecting closing tag '"+tagName+"'";
495 reportError(yyscanner,msg);
496 }
497
498 debugEnd();
499}

References fileName, msg, p and reportError.

Referenced by LayoutDocManager::init, LayoutDocManager::parse and parseTagFile.

Private Member Functions

fileName()

std::string XMLParser::fileName ()
virtual

Declaration at line 107 of file xml.h, definition at line 507 of file xml.l.

507std::string XMLParser::fileName() const
508{
509 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
510 return yyextra->fileName;
511}

Reference p.

Referenced by parse.

lineNr()

int XMLParser::lineNr ()
virtual

Declaration at line 106 of file xml.h, definition at line 501 of file xml.l.

502{
503 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
504 return yyextra->lineNr;
505}

Reference p.

Private Member Attributes

p

std::unique_ptr<Private> XMLParser::p

Definition at line 109 of file xml.h.

109 std::unique_ptr<Private> p;

Referenced by fileName, lineNr, parse, XMLParser and ~XMLParser.


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


Generated via doxygen2docusaurus by Doxygen 1.14.0.