43 #include <libxml/parser.h> 44 #include <libxml/parserInternals.h> 47 class 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, ...);
69 fSAXHandler =
new xmlSAXHandler;
70 memset(fSAXHandler, 0,
sizeof(xmlSAXHandler));
72 fSAXHandler->startDocument =
73 (startDocumentSAXFunc)TSAXParserCallback::StartDocument;
74 fSAXHandler->endDocument =
75 (endDocumentSAXFunc)TSAXParserCallback::EndDocument;
76 fSAXHandler->startElement =
77 (startElementSAXFunc)TSAXParserCallback::StartElement;
78 fSAXHandler->endElement =
79 (endElementSAXFunc)TSAXParserCallback::EndElement;
80 fSAXHandler->characters =
81 (charactersSAXFunc)TSAXParserCallback::Characters;
82 fSAXHandler->comment =
83 (commentSAXFunc)TSAXParserCallback::Comment;
84 fSAXHandler->cdataBlock =
85 (cdataBlockSAXFunc)TSAXParserCallback::CdataBlock;
86 fSAXHandler->warning =
90 fSAXHandler->fatalError =
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;
213 fContext->sax = fSAXHandler;
214 fContext->userData =
this;
218 xmlParseDocument(fContext);
220 fContext->sax = oldSAX;
222 if (!fContext->wellFormed && fParseCode == 0) {
243 fContext = xmlCreateFileParserCtxt(filename);
260 fContext = xmlCreateMemoryParserCtxt(contents, len);
270 void TSAXParserCallback::StartDocument(
void *fParser)
279 void TSAXParserCallback::EndDocument(
void *fParser)
289 void TSAXParserCallback::StartElement(
void *fParser,
const xmlChar *
name,
296 for (
const xmlChar **cur = p; cur && *cur; cur += 2) {
298 (
const char*)*(cur + 1)));
311 void TSAXParserCallback::EndElement(
void *fParser,
const xmlChar *
name)
322 void TSAXParserCallback::Characters(
void *fParser,
const xmlChar *ch,
327 char *str =
new char[len+1];
328 strlcpy(str, (
const char*) ch, len+1);
340 void 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);
389 if (errorcode < 0 && parser->GetStopOnError()) {
399 void TSAXParserCallback::FatalError(
void *fParser,
const char *
va_(fmt), ...)
407 va_start(arg,
va_(fmt));
408 vsnprintf(buffer, 2048,
va_(fmt), arg);
423 void 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++) {
459 if (CheckConnectArgs(
this, this->IsA(), kFunctionsName[i],
460 cl, kFunctionsName[i]) != -1)
461 Connect(kFunctionsName[i], handlerName, handler, kFunctionsName[i]);
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
virtual void OnComment(const char *text)
Emit a signal for OnComment, where text is the comment.
virtual Int_t ParseBuffer(const char *contents, Int_t len)
It parse the contents, instead of a file.
TSAXParser is a subclass of TXMLParser, it is a wraper class to libxml library.
virtual void OnStartDocument()
Emit a signal for OnStartDocument.
virtual void OnWarning(const char *text)
Emit a signal for OnWarning, where text is the warning.
virtual Int_t OnError(const char *text)
Emit a signal for OnError, where text is the error and it returns the Parse Error Code...
virtual void SetParseCode(Int_t code)
Set the parse code:
virtual ~TSAXParser()
TSAXParser desctructor.
virtual void OnEndElement(const char *name)
Emit a signal for OnEndElement, where name is the Element's name.
virtual void StopParser()
Stops parsing.
void Error(const char *location, const char *msgfmt,...)
virtual Int_t Parse()
This function parses the xml file, by initializing the parser and checks whether the parse context is...
virtual void OnEndDocument()
Emit a signal for OnEndDocument.
The ROOT global object gROOT contains a list of all defined classes.
TXMLAttribute is the attribute of an Element.
void Warning(const char *location, const char *msgfmt,...)
TSAXParser()
Create SAX parser.
virtual void OnCdataBlock(const char *text, Int_t len)
Emit a signal for OnCdataBlock.
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 ConnectToHandler(const char *handlerName, void *handler)
A default TSAXParser to a user-defined Handler connection function.
virtual void OnCharacters(const char *characters)
Emit a signal for OnCharacters, where characters are the characters outside of tags.
virtual void Add(TObject *obj)
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 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 Int_t ParseFile(const char *filename)
It creates the parse context of the xml file, where the xml file name is filename.
const char * Data() const