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

xmli::Parser Class Reference

Construct a parser for XML text. More...

#include <Parser.h>

List of all members.

Public Member Functions

 Parser ()
 ~Parser ()
void ParseFile (const char *filename)
void ParseText (const char *text)

Static Public Member Functions

const char * GetCurrentSource ()

Private Attributes

SAX2XMLReader * fParser
 SAX2 parser.

DefaultHandler * fHandler
 Handler for start and end element events.


Static Private Attributes

std::string fSource = ""
 XML source which is being parsed.

int fCount = 0
 Object count for this class.


Detailed Description

Construct a parser for XML text.

Definition at line 16 of file Parser.h.


Constructor & Destructor Documentation

xmli::Parser::Parser  ) 
 

Definition at line 29 of file Parser.cxx.

References fCount, fHandler, and fParser.

00029                    :
00030   fParser(0),
00031   fHandler(0)
00032 {
00033 //======================================================================
00034 // Create parser. If this is the first one created, initialize xercesc.
00035 //======================================================================
00036   ++fCount;
00037   
00038   if (fCount<=1) XMLPlatformUtils::Initialize();
00039 
00040   fParser = XMLReaderFactory::createXMLReader();
00041 
00042   fParser->setFeature(XMLUni::fgSAX2CoreValidation, true);
00043   fParser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
00044 
00045   fHandler = new xmli::SAX2DefaultHandler();
00046 
00047   fParser->setContentHandler(fHandler);
00048 }

xmli::Parser::~Parser  ) 
 

Definition at line 52 of file Parser.cxx.

References fCount, fHandler, and fParser.

00053 {
00054 //======================================================================
00055 // Delete parser. If there are no parsers left, shutdown xercesc.
00056 //======================================================================
00057   --fCount;
00058 
00059   if (fParser)  { delete fParser;  fParser  = 0; }
00060   if (fHandler) { delete fHandler; fHandler = 0; }
00061   
00062   if (fCount==0) XMLPlatformUtils::Terminate();
00063 }


Member Function Documentation

const char * xmli::Parser::GetCurrentSource  )  [static]
 

Definition at line 18 of file Parser.cxx.

References fSource.

Referenced by cfg::configBuilder::Build(), xmli::SAX2Handler::EndElement(), and xmli::SAX2Handler::~SAX2Handler().

00019 {
00020 //======================================================================
00023 //======================================================================
00024   return fSource.c_str();
00025 }

void xmli::Parser::ParseFile const char *  filename  ) 
 

Definition at line 84 of file Parser.cxx.

References fParser, and fSource.

Referenced by main(), and xmli::ReadFile().

00085 {
00086 //======================================================================
00087 // Parse a file
00088 //======================================================================
00089   fSource = filename;
00090   fParser->parse(filename);
00091 }

void xmli::Parser::ParseText const char *  text  ) 
 

Definition at line 67 of file Parser.cxx.

References fParser, and fSource.

Referenced by xmli::ReadString().

00068 {
00069   int         len   = strlen(text);
00070   const char* bufid = "xmltext";
00071   MemBufInputSource* 
00072     membuf = new MemBufInputSource((const XMLByte*)text,
00073                                    len,
00074                                    bufid,
00075                                    false);
00076   fSource = bufid;
00077   fParser->parse(*membuf);
00078 
00079   delete membuf;
00080 }


Member Data Documentation

int xmli::Parser::fCount = 0 [static, private]
 

Object count for this class.

Definition at line 14 of file Parser.cxx.

Referenced by Parser(), and ~Parser().

DefaultHandler* xmli::Parser::fHandler [private]
 

Handler for start and end element events.

Definition at line 31 of file Parser.h.

Referenced by Parser(), and ~Parser().

SAX2XMLReader* xmli::Parser::fParser [private]
 

SAX2 parser.

Definition at line 30 of file Parser.h.

Referenced by ParseFile(), Parser(), ParseText(), and ~Parser().

std::string xmli::Parser::fSource = "" [static, private]
 

XML source which is being parsed.

Definition at line 13 of file Parser.cxx.

Referenced by GetCurrentSource(), ParseFile(), and ParseText().


The documentation for this class was generated from the following files:
Generated on Fri Jul 25 02:05:55 2008 for NOvA Offline by doxygen 1.3.5