S A X Handler

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

Author: Sergey Linev
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Saturday, September 18, 2021 at 10:02 AM.

In [1]:
%%cpp -d
#include <Riostream.h>
#include <TList.h>
#include <TSAXParser.h>
#include <TXMLAttr.h>

class SaxHandler {
   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);

A helper function is created:

In [2]:
%%cpp -d
void SaxHandler::OnEndDocument()
   cout << endl;

A helper function is created:

In [3]:
%%cpp -d
void SaxHandler::OnStartElement(const char *name, const TList *attributes)
   cout << "<" << name;

   TXMLAttr *attr;

   TIter next(attributes);
   while ((attr = (TXMLAttr*) next())) {
      cout << " " << attr->GetName() << "=\"" << attr->GetValue() << "\"";

   cout  << ">";

A helper function is created:

In [4]:
%%cpp -d
void SaxHandler::OnEndElement(const char *name)
   cout << "</" << name << ">";

A helper function is created:

In [5]:
%%cpp -d
void SaxHandler::OnCharacters(const char *characters)
   cout << characters;

A helper function is created:

In [6]:
%%cpp -d
void SaxHandler::OnComment(const char *text)
   cout << "<!--" << text << "-->";

A helper function is created:

In [7]:
%%cpp -d
void SaxHandler::OnWarning(const char *text)
   cout << "Warning: " << text << endl;

A helper function is created:

In [8]:
%%cpp -d
void SaxHandler::OnError(const char *text)
   cerr << "Error: " << text << endl ;

A helper function is created:

In [9]:
%%cpp -d
void SaxHandler::OnFatalError(const char *text)
   cerr << "FatalError: " << text << endl ;

A helper function is created:

In [10]:
%%cpp -d
void SaxHandler::OnCdataBlock(const char *text, Int_t len)
   cout << "OnCdataBlock() " << text;
In [11]:
TSAXParser *saxParser = new TSAXParser();
SaxHandler *saxHandler = new SaxHandler();

saxParser->ConnectToHandler("SaxHandler", saxHandler);
TString dir = gROOT->GetTutorialDir();
<gjob:Helping xmlns:gjob="http://www.gnome.org/some-location">

      <gjob:Project id="3" time="100" priority="high"></gjob:Project>

         <gjob:Modified>Mon, 07 Jun 1999 20:27:45 -0400 MET DST</gjob:Modified>
        <gjob:Salary>USD 0.00</gjob:Salary>


        <gjob:Person>Nathan Clemons</gjob:Person>
        <gjob:Email>[email protected]</gjob:Email>

      The program should be released as free software, under the GPL.


      A GNOME based system that will allow a superuser to configure
      compressed and uncompressed files and/or file systems to be backed
      up with a supported media in the system.  This should be able to
      perform via find commands generating a list of files that are passed
      to tar, dd, cpio, cp, gzip, etc., to be directed to the tape machine
      or via operations performed on the filesystem itself. Email
      notification and GUI status display very important.