Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
SAXHandler.C File Reference

Detailed Description

ROOT implementation of a simple SAX Handler.

This handler uses TSAXParser, a SAX Parser using the SAX interface of libxml2. This script will output all elements of the original xml file, if successfully parsed.

To run this program do:

.x SAXHandler.C

Requires: saxexample.xml

#include <Riostream.h>
#include <TList.h>
#include <TSAXParser.h>
#include <TXMLAttr.h>
class SaxHandler {
public:
SaxHandler() { }
void OnStartDocument() { }
void OnEndDocument();
void OnStartElement(const char*, const TList*);
void OnEndElement(const char*);
void OnCharacters(const char*);
void OnComment(const char*);
void OnWarning(const char*);
void OnError(const char*);
void OnFatalError(const char*);
void OnCdataBlock(const char*, Int_t);
};
void SaxHandler::OnEndDocument()
{
cout << endl;
}
void SaxHandler::OnStartElement(const char *name, const TList *attributes)
{
cout << "<" << name;
TIter next(attributes);
while ((attr = (TXMLAttr*) next())) {
cout << " " << attr->GetName() << "=\"" << attr->GetValue() << "\"";
}
cout << ">";
}
void SaxHandler::OnEndElement(const char *name)
{
cout << "</" << name << ">";
}
void SaxHandler::OnCharacters(const char *characters)
{
cout << characters;
}
void SaxHandler::OnComment(const char *text)
{
cout << "<!--" << text << "-->";
}
void SaxHandler::OnWarning(const char *text)
{
cout << "Warning: " << text << endl;
}
void SaxHandler::OnError(const char *text)
{
cerr << "Error: " << text << endl ;
}
void SaxHandler::OnFatalError(const char *text)
{
cerr << "FatalError: " << text << endl ;
}
void SaxHandler::OnCdataBlock(const char *text, Int_t len)
{
cout << "OnCdataBlock() " << text;
}
void SAXHandler()
{
TSAXParser *saxParser = new TSAXParser();
SaxHandler *saxHandler = new SaxHandler();
saxParser->ConnectToHandler("SaxHandler", saxHandler);
TString dir = gROOT->GetTutorialDir();
saxParser->ParseFile(dir+"/xml/saxexample.xml");
}
int Int_t
Definition RtypesCore.h:45
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
Option_t Option_t TPoint TPoint const char text
char name[80]
Definition TGX11.cxx:110
#define gROOT
Definition TROOT.h:406
A doubly linked list.
Definition TList.h:38
TSAXParser is a subclass of TXMLParser, it is a wraper class to libxml library.
Definition TSAXParser.h:23
virtual void ConnectToHandler(const char *handlerName, void *handler)
A default TSAXParser to a user-defined Handler connection function.
Int_t ParseFile(const char *filename) override
It creates the parse context of the xml file, where the xml file name is filename.
Basic string class.
Definition TString.h:139
TXMLAttribute is the attribute of an Element.
Definition TXMLAttr.h:18
Author
Sergey Linev

Definition in file SAXHandler.C.