43#include <libxml/parser.h>
44#include <libxml/parserInternals.h>
47class TSAXParserCallback {
49 static void StartDocument(
void *fParser);
50 static void EndDocument(
void *fParser);
51 static void StartElement(
void *fParser,
const xmlChar *
name,
const xmlChar **p);
52 static void EndElement(
void *fParser,
const xmlChar *
name);
53 static void Characters(
void *fParser,
const xmlChar *ch,
Int_t len);
54 static void Comment(
void *fParser,
const xmlChar *value);
55 static void CdataBlock(
void *fParser,
const xmlChar *value,
Int_t len);
56 static void Warning(
void *fParser,
const char *fmt, ...);
57 static void Error(
void *fParser,
const char *fmt, ...);
58 static void FatalError(
void *fParser,
const char *fmt, ...);
73 (startDocumentSAXFunc)TSAXParserCallback::StartDocument;
75 (endDocumentSAXFunc)TSAXParserCallback::EndDocument;
77 (startElementSAXFunc)TSAXParserCallback::StartElement;
79 (endElementSAXFunc)TSAXParserCallback::EndElement;
81 (charactersSAXFunc)TSAXParserCallback::Characters;
83 (commentSAXFunc)TSAXParserCallback::Comment;
85 (cdataBlockSAXFunc)TSAXParserCallback::CdataBlock;
91 (fatalErrorSAXFunc)TSAXParserCallback::FatalError;
109 Emit(
"OnStartDocument()");
117 Emit(
"OnEndDocument()");
130 args[1] = (
Long_t)attributes;
132 Emit(
"OnStartElement(const char *, const TList *)", args);
140 Emit(
"OnEndElement(const char *)",
name);
149 Emit(
"OnCharacters(const char *)", characters);
157 Emit(
"OnComment(const char *)",
text);
165 Emit(
"OnWarning(const char *)",
text);
174 Emit(
"OnError(const char *)",
text);
184 Emit(
"OnFatalError(const char *)",
text);
197 Emit(
"OnCdataBlock(const char *, Int_t)", args);
212 xmlSAXHandlerPtr oldSAX =
fContext->sax;
243 fContext = xmlCreateFileParserCtxt(filename);
260 fContext = xmlCreateMemoryParserCtxt(contents, len);
270void TSAXParserCallback::StartDocument(
void *fParser)
279void TSAXParserCallback::EndDocument(
void *fParser)
289void TSAXParserCallback::StartElement(
void *fParser,
const xmlChar *
name,
296 for (
const xmlChar **cur = p; cur && *cur; cur += 2) {
298 (
const char*)*(cur + 1)));
311void TSAXParserCallback::EndElement(
void *fParser,
const xmlChar *
name)
322void TSAXParserCallback::Characters(
void *fParser,
const xmlChar *ch,
327 char *str =
new char[len+1];
328 strlcpy(str, (
const char*) ch, len+1);
340void TSAXParserCallback::Comment(
void *fParser,
const xmlChar *value)
357 va_start(arg,
va_(fmt));
358 vsnprintf(buffer, 2048,
va_(fmt), arg);
378 va_start(arg,
va_(fmt));
379 vsnprintf(buffer, 2048,
va_(fmt), arg);
384 errorcode = parser->
OnError(buff.Data());
389 if (errorcode < 0 && parser->GetStopOnError()) {
399void TSAXParserCallback::FatalError(
void *fParser,
const char *
va_(fmt), ...)
407 va_start(arg,
va_(fmt));
408 vsnprintf(buffer, 2048,
va_(fmt), arg);
423void TSAXParserCallback::CdataBlock(
void *fParser,
const xmlChar *value,
443 const TString kFunctionsName [] = {
446 "OnStartElement(const char *, const TList *)",
447 "OnEndElement(const char *)",
448 "OnCharacters(const char *)",
449 "OnComment(const char *)",
450 "OnWarning(const char *)",
451 "OnError(const char *)",
452 "OnFatalError(const char *)",
453 "OnCdataBlock(const char *, Int_t)"
458 for (
Int_t i = 0; i < 10; i++) {
460 cl, kFunctionsName[i]) != -1)
461 Connect(kFunctionsName[i], handlerName, handler, kFunctionsName[i]);
void Error(const char *location, const char *msgfmt,...)
void Warning(const char *location, const char *msgfmt,...)
TClass instances represent classes, structs and namespaces in the ROOT type system.
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
virtual void Add(TObject *obj)
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
static Int_t CheckConnectArgs(TQObject *sender, TClass *sender_class, const char *signal, TClass *receiver_class, const char *slot)
Checking of consitency of sender/receiver methods/arguments.
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
TSAXParser is a subclass of TXMLParser, it is a wraper class to libxml library.
virtual void OnWarning(const char *text)
Emit a signal for OnWarning, where text is the warning.
virtual void OnCdataBlock(const char *text, Int_t len)
Emit a signal for OnCdataBlock.
virtual Int_t ParseBuffer(const char *contents, Int_t len)
It parse the contents, instead of a file.
virtual Int_t Parse()
This function parses the xml file, by initializing the parser and checks whether the parse context is...
virtual ~TSAXParser()
TSAXParser desctructor.
virtual Int_t OnFatalError(const char *text)
Emit a signal for OnFactalError, where text is the error and it returns the Parse Error Code,...
virtual Int_t ParseFile(const char *filename)
It creates the parse context of the xml file, where the xml file name is filename.
virtual void OnCharacters(const char *characters)
Emit a signal for OnCharacters, where characters are the characters outside of tags.
TSAXParser()
Create SAX parser.
virtual void OnComment(const char *text)
Emit a signal for OnComment, where text is the comment.
virtual void OnStartElement(const char *name, const TList *attr)
Emit a signal for OnStarElement, where name is the Element's name and attribute is a TList of (TObjSt...
virtual void OnEndDocument()
Emit a signal for OnEndDocument.
virtual void ConnectToHandler(const char *handlerName, void *handler)
A default TSAXParser to a user-defined Handler connection function.
virtual void OnStartDocument()
Emit a signal for OnStartDocument.
virtual void OnEndElement(const char *name)
Emit a signal for OnEndElement, where name is the Element's name.
virtual Int_t OnError(const char *text)
Emit a signal for OnError, where text is the error and it returns the Parse Error Code,...
_xmlSAXHandler * fSAXHandler
libxml2 SAX handler
TXMLAttribute is the attribute of an Element.
virtual void InitializeContext()
Initialize parser parameters, such as, disactivate non-standards libxml1 features,...
virtual void SetParseCode(Int_t code)
Set the parse code:
_xmlParserCtxt * fContext
Parse the xml file.
Int_t fParseCode
To keep track of the errorcodes.
virtual void ReleaseUnderlying()
To release any existing document.
virtual void StopParser()
Stops parsing.