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:
Requires: saxexample.xml
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 <<
" " <<
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 ;
}
{
cout <<
"OnCdataBlock() " <<
text;
}
void SAXHandler()
{
SaxHandler *saxHandler = new SaxHandler();
saxParser->
ParseFile(dir+
"/xml/saxexample.xml");
}
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
TSAXParser is a subclass of TXMLParser, it is a wraper class to libxml library.
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.
TXMLAttribute is the attribute of an Element.
- Author
- Sergey Linev
Definition in file SAXHandler.C.