Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

xmli::SAX2Handler Class Reference

SAX2 handler for each tag defined in an XML file. More...

#include <SAX2Handler.h>

List of all members.

Public Member Functions

 SAX2Handler ()
virtual ~SAX2Handler ()
virtual void StartElement (const std::string &uri, const std::string &localname, const std::string &qname, const AttributeList &attrs)
virtual void Characters (const std::string &chars)
virtual void EndElement (const std::string &uri, const std::string &localname, const std::string &qname)

Private Attributes

std::string fUri
 Tag "universal reference".
std::string fLocalName
 Local name of tag.
std::string fQname
 Qualified name of tag.
std::vector< AttributefAttributes
 Set of tag attributes.
std::string fCharacters
 Text buffer.
int fCount
 Count begin/end tag events.


Detailed Description

SAX2 handler for each tag defined in an XML file.

This class is used to hold the state of parsing between the startElement and endElement calls

Definition at line 19 of file SAX2Handler.h.


Constructor & Destructor Documentation

xmli::SAX2Handler::SAX2Handler  ) 
 

Definition at line 16 of file SAX2Handler.cxx.

00016                              : 
00017   fUri       (""),
00018   fLocalName (""),
00019   fQname     (""),
00020   fCharacters(""),
00021   fCount     (0 )
00022 { }

xmli::SAX2Handler::~SAX2Handler  )  [virtual]
 

Definition at line 26 of file SAX2Handler.cxx.

References fCount, fLocalName, and xmli::Parser::GetCurrentSource().

00027 {
00028   // Check that the begin and end tag counts match
00029   if (fCount>0) {
00030     std::cerr << "xmli::SAX2Handler::" << __LINE__ 
00031               << " Tag '" << fLocalName << "' not closed "
00032               << " in " << xmli::Parser::GetCurrentSource()
00033               << " (count = " << fCount << ")" 
00034               << std::endl;
00035     abort();
00036   }
00037   if (fCount<0) {
00038     std::cerr << "xmli::SAX2Handler::" << __LINE__ 
00039               << " Tag '" << fLocalName << "' closed but not openned"
00040               << " in " << xmli::Parser::GetCurrentSource()
00041               << " (count = " << fCount << ")" 
00042               << std::endl;
00043     abort();
00044   }
00045 }


Member Function Documentation

void xmli::SAX2Handler::Characters const std::string &  chars  )  [virtual]
 

Definition at line 76 of file SAX2Handler.cxx.

References fCharacters.

Referenced by xmli::SAX2DefaultHandler::characters().

00077 {
00078 //======================================================================
00079 // Spool the characters inside the element to the local buffer
00080 //======================================================================
00081   if (gsDebug) {
00082     std::cerr << "[Charaters] " << chars << std::endl;
00083   }
00084   fCharacters += chars;
00085 }

void xmli::SAX2Handler::EndElement const std::string &  uri,
const std::string &  localname,
const std::string &  qname
[virtual]
 

Definition at line 89 of file SAX2Handler.cxx.

References xmli::Builder::Build(), fAttributes, fCharacters, xmli::BuilderFac::Get(), xmli::Parser::GetCurrentSource(), and xmli::BuilderFac::Instance().

Referenced by xmli::SAX2DefaultHandler::endElement().

00092 {
00093 //======================================================================
00094 // Handle the end tag
00095 //======================================================================
00096 
00097   // These better match what we saw in the StartElement or we're in
00098   // big trouble
00099   if (uri       != fUri)       abort();
00100   if (localname != fLocalName) abort();
00101   if (qname     != fQname)     abort();
00102   --fCount;
00103 
00104   // Check if there is a builder defined for this tag. If yes, pass
00105   // the accumulated data off to the builder
00106   xmli::Builder* b = xmli::BuilderFac::Instance().Get(localname);
00107   if (b) b->Build(fAttributes, fCharacters);
00108   else {
00109     std::cerr << "xmli::SAX2Handler:" << __LINE__ 
00110               << " No no handler for tag '"
00111               << localname << "' from file "
00112               << xmli::Parser::GetCurrentSource()
00113               << std::endl;
00114     abort();
00115   }
00116   if (gsDebug) {
00117     std::cerr 
00118       << "[EndElement]" 
00119       << " [ uri=" << uri << "]"
00120       << " [ localname=" << localname << "]"
00121       << " [ qname=" << qname << "]"
00122       << " [ builder=" << b << "]"
00123       << std::endl;
00124   }
00125 }

void xmli::SAX2Handler::StartElement const std::string &  uri,
const std::string &  localname,
const std::string &  qname,
const AttributeList attrs
[virtual]
 

Definition at line 49 of file SAX2Handler.cxx.

References fAttributes, fCharacters, fLocalName, fQname, and fUri.

Referenced by xmli::SAX2DefaultHandler::startElement().

00053 {
00054 //======================================================================
00055 // Called at start of tag element
00056 //======================================================================
00057   fUri        = uri;
00058   fLocalName  = localname;
00059   fQname      = qname;
00060   fAttributes = attrs;
00061   fCharacters = "";
00062 
00063   ++fCount;
00064   if (gsDebug) {
00065     std::cerr 
00066       << "[StartElement]" 
00067       << " [ uri=" << uri << "]"
00068       << " [ localname=" << localname << "]"
00069       << " [ qname=" << qname << "]"
00070       << std::endl;
00071   }
00072 }  


Member Data Documentation

std::vector<Attribute> xmli::SAX2Handler::fAttributes [private]
 

Set of tag attributes.

Definition at line 36 of file SAX2Handler.h.

Referenced by EndElement(), and StartElement().

std::string xmli::SAX2Handler::fCharacters [private]
 

Text buffer.

Definition at line 37 of file SAX2Handler.h.

Referenced by Characters(), EndElement(), and StartElement().

int xmli::SAX2Handler::fCount [private]
 

Count begin/end tag events.

Definition at line 38 of file SAX2Handler.h.

Referenced by ~SAX2Handler().

std::string xmli::SAX2Handler::fLocalName [private]
 

Local name of tag.

Definition at line 34 of file SAX2Handler.h.

Referenced by StartElement(), and ~SAX2Handler().

std::string xmli::SAX2Handler::fQname [private]
 

Qualified name of tag.

Definition at line 35 of file SAX2Handler.h.

Referenced by StartElement().

std::string xmli::SAX2Handler::fUri [private]
 

Tag "universal reference".

Definition at line 33 of file SAX2Handler.h.

Referenced by StartElement().


The documentation for this class was generated from the following files:
Generated on Mon Nov 23 04:45:35 2009 for NOvA Offline by  doxygen 1.3.9.1