Version: 8.3.0
xmlParserBase Class Reference

base class for xml parsers, runtime independant More...

#include <xmlParserBase.hxx>

Inheritance diagram for xmlParserBase:
Collaboration diagram for xmlParserBase:

Public Member Functions

void setAttribute (std::string key, std::string value)
 
std::string getAttribute (std::string key)
 
virtual void addData (std::string value)
 
virtual void init (const xmlChar **p, xmlParserBase *father=0)
 

Static Public Member Functions

static void XMLCALL start_document (void *userData)
 
static void XMLCALL end_document (void *userData)
 
static void XMLCALL start_element (void *userData, const xmlChar *name, const xmlChar **p)
 
static void XMLCALL end_element (void *userData, const xmlChar *name)
 
static void XMLCALL characters (void *userData, const xmlChar *ch, int len)
 
static void XMLCALL comment (void *userData, const xmlChar *value)
 
static void XMLCALL warning (void *userData, const char *fmt,...)
 
static void XMLCALL error (void *userData, const char *fmt,...)
 
static void XMLCALL fatal_error (void *userData, const char *fmt,...)
 
static void XMLCALL cdata_block (void *userData, const xmlChar *value, int len)
 
static void cleanGarbage ()
 
static int getGarbageSize ()
 
static void XML_SetUserData (_xmlParserCtxt *ctxt, xmlParserBase *parser)
 

Public Attributes

std::map< std::string, int > counts
 

Static Public Attributes

static _xmlParserCtxt * _xmlParser
 
static std::stack
< xmlParserBase * > 
_stackParser
 

Protected Member Functions

void getAttributes (const xmlChar **p)
 
virtual void onStart (const XML_Char *elem, const xmlChar **p)
 
virtual void onEnd (const XML_Char *name)
 
virtual void charData (std::string data)
 
virtual void incrCount (const XML_Char *elem)
 
virtual void end ()
 
virtual void stopParse (std::string what)
 

Protected Attributes

std::map< std::string,
std::string > 
_mapAttrib
 
std::string _data
 
xmlParserBase_father
 

Static Protected Attributes

static std::list< xmlParserBase * > _garbage
 

Detailed Description

base class for xml parsers, runtime independant

Definition at line 51 of file xmlParserBase.hxx.

Member Function Documentation

void xmlParserBase::addData ( std::string  value)
virtual

Add data on the data attribute of the parser object dedicated to an xml tag

Reimplemented in outputParser, YACS::ENGINE::dataParser, YACS::ENGINE::arrayParser, YACS::ENGINE::valueParser, and YACS::ENGINE::portParser.

Definition at line 267 of file xmlParserBase.cxx.

268 {
269  // DEBTRACE("xmlParserBase::addData()");
270  _data += value;
271 }
void XMLCALL xmlParserBase::cdata_block ( void *  userData,
const xmlChar *  value,
int  len 
)
static

callback called for CDATA inside tags:

<tag>![CDATA[content]]></tag> 

used only by libxml2

Definition at line 204 of file xmlParserBase.cxx.

References charData().

Referenced by xmlReader::parse().

207 {
208  //DEBTRACE("xmlParserBase::cdata_block");
209  xmlParserBase *currentParser = static_cast<xmlParserBase *> (userData);
210  string data((char*)value,len);
211  currentParser->charData(data);
212 }
void XMLCALL xmlParserBase::characters ( void *  userData,
const xmlChar *  ch,
int  len 
)
static

callback called for significant characters inside tags:

<tag>content</tag> 

or outside tags, like space or new line; get also the CDATA tags:

<tag>![CDATA[content]]></tag> 

Definition at line 108 of file xmlParserBase.cxx.

References charData().

Referenced by xmlReader::parse().

111 {
112  //DEBTRACE("xmlParserBase::characters " << len);
113  xmlParserBase *currentParser = (xmlParserBase *) (userData);
114  string data((char*)ch,len);
115  currentParser->charData(data);
116 }
void xmlParserBase::charData ( std::string  data)
protectedvirtual

to be specialized following the kind of xml tag

Reimplemented in YACS::ENGINE::sampleParser, YACS::ENGINE::loopPortParser, YACS::ENGINE::simpleTypeParser, YACS::ENGINE::attrParser, and YACS::ENGINE::stateParser.

Definition at line 299 of file xmlParserBase.cxx.

Referenced by cdata_block(), and characters().

300 {
301 }
void xmlParserBase::cleanGarbage ( )
static

Definition at line 214 of file xmlParserBase.cxx.

Referenced by xmlReader::parse().

215 {
216  while (!_garbage.empty())
217  {
218  delete (_garbage.front());
219  _garbage.pop_front();
220  }
221 }
void XMLCALL xmlParserBase::comment ( void *  userData,
const xmlChar *  value 
)
static

callback usable only with libxml2

Definition at line 122 of file xmlParserBase.cxx.

Referenced by xmlReader::parse().

124 {
125  //DEBTRACE("xmlParserBase::comment");
126  xmlParserBase *currentParser = static_cast<xmlParserBase *> (userData);
127 }
void xmlParserBase::end ( )
protectedvirtual

to be specialized for each kind of xml tag

Definition at line 318 of file xmlParserBase.cxx.

Referenced by end_element().

319 {
320 }
void XMLCALL xmlParserBase::end_document ( void *  userData)
static

callback usable only with libxml2

Definition at line 63 of file xmlParserBase.cxx.

Referenced by xmlReader::parse().

64 {
65  //DEBTRACE("xmlParserBase::end_document");
66  xmlParserBase *currentParser = static_cast<xmlParserBase *> (userData);
67 }
void XMLCALL xmlParserBase::end_element ( void *  userData,
const xmlChar *  name 
)
static

callback called on end of an xml element:

</name> 

Definition at line 88 of file xmlParserBase.cxx.

References DEBTRACE, end(), onEnd(), tochar(), and XML_Char.

Referenced by xmlReader::parse().

90 {
91  //DEBTRACE("xmlParserBase::end_element");
92  const XML_Char *aName = tochar(name);
93  xmlParserBase *childParser = static_cast<xmlParserBase *> (userData);
94  _garbage.push_back(_stackParser.top());
95  DEBTRACE("xmlParserBase::end_element " << _garbage.size());
96  _stackParser.pop();
98  childParser->onEnd(aName);
99  childParser->end();
100  }
void XMLCALL xmlParserBase::error ( void *  userData,
const char *  fmt,
  ... 
)
static

callback usable only with libxml2

Definition at line 156 of file xmlParserBase.cxx.

References DEBTRACE.

Referenced by xmlReader::parse().

158 {
159  DEBTRACE("xmlParserBase::error");
160  xmlParserBase *currentParser = static_cast<xmlParserBase *> (userData);
161  va_list args;
162  va_start(args, fmt);
163  string format = "%s";
164  if (format == fmt)
165  {
166  char* parv;
167  parv = va_arg(args, char*);
168  cerr << parv ;
169  xmlParserBase *currentParser = (xmlParserBase *) userData;
170  //cerr << currentParser->element << endl;
171  }
172  else cerr << __FILE__ << " [" << __LINE__ << "] : "
173  << "error format not taken into account: " << fmt << endl;
174  va_end(args);
175 }
void XMLCALL xmlParserBase::fatal_error ( void *  userData,
const char *  fmt,
  ... 
)
static

callback usable only with libxml2

Definition at line 181 of file xmlParserBase.cxx.

References DEBTRACE.

Referenced by xmlReader::parse().

183 {
184  DEBTRACE("xmlParserBase::fatal_error");
185  xmlParserBase *currentParser = static_cast<xmlParserBase *> (userData);
186  va_list args;
187  va_start(args, fmt);
188  string format = "%s";
189  if (format == fmt)
190  {
191  char* parv;
192  parv = va_arg(args, char*);
193  cerr << parv ;
194  }
195  else cerr << __FILE__ << " [" << __LINE__ << "] : "
196  << "error format not taken into account: " << fmt << endl;
197  va_end(args);
198 }
std::string xmlParserBase::getAttribute ( std::string  key)

Gets an attribute value given a string key. If the key does not exist, throws an Exception.

Definition at line 254 of file xmlParserBase.cxx.

255 {
256  if (_mapAttrib.find(key) == _mapAttrib.end())
257  {
258  string what = "Attribute does not exist: " + key;
259  throw Exception(what);
260  }
261  return _mapAttrib[key];
262 }
void xmlParserBase::getAttributes ( const xmlChar **  p)
protected

Stores the tag attributes on a map. The map is an attribute of the parser object dedicated to the current xml tag

Definition at line 227 of file xmlParserBase.cxx.

Referenced by YACS::ENGINE::sampleParser::init().

228 {
229  if (p) while (*p)
230  {
231  string attributeName = (char*)*p;
232  //cerr << "attribute name " << attributeName << endl;
233  p++;
234  string attributeValue = (char*)*p;
235  //cerr << "attribute value " << attributeValue << endl;
236  p++;
237  _mapAttrib[attributeName] = attributeValue;
238  }
239 }
static int xmlParserBase::getGarbageSize ( )
inlinestatic

Definition at line 78 of file xmlParserBase.hxx.

References _garbage.

Referenced by xmlReader::parse().

78 {return _garbage.size(); };
void xmlParserBase::incrCount ( const XML_Char elem)
protectedvirtual

May be specialized for each kind of xml tag. Counts the number of tag occurences of a given type inside a context.

Definition at line 307 of file xmlParserBase.cxx.

Referenced by start_element().

308 {
309  if(counts.find(elem)==counts.end())
310  counts[elem]=1;
311  else
312  counts[elem]=counts[elem]+1;
313 }
void xmlParserBase::init ( const xmlChar **  p,
xmlParserBase father = 0 
)
virtual

all parsers must know their father parser (father tag), in order to set values or attributes in father.

Reimplemented in YACS::ENGINE::sampleParser, outputParser, YACS::ENGINE::loopPortParser, YACS::ENGINE::simpleTypeParser, YACS::ENGINE::dataParser, YACS::ENGINE::arrayParser, YACS::ENGINE::valueParser, YACS::ENGINE::portParser, YACS::ENGINE::attrParser, YACS::ENGINE::nodeParser, YACS::ENGINE::graphParser, and YACS::ENGINE::stateParser.

Definition at line 277 of file xmlParserBase.cxx.

Referenced by xmlReader::parse().

278 {
279  _father = father;
280 }
void xmlParserBase::onEnd ( const XML_Char name)
protectedvirtual

to be specialized for each kind of xml tag

Reimplemented in outputParser.

Definition at line 292 of file xmlParserBase.cxx.

Referenced by end_element().

293 {
294 }
void xmlParserBase::onStart ( const XML_Char elem,
const xmlChar **  p 
)
protectedvirtual

to be specialized for each kind of xml tag

Reimplemented in outputParser.

Definition at line 285 of file xmlParserBase.cxx.

Referenced by start_element().

286 {
287 }
void xmlParserBase::setAttribute ( std::string  key,
std::string  value 
)

Stores an attribute (key, value) on the map attribute. used for attributes defined at another tag level (child tags).

Definition at line 245 of file xmlParserBase.cxx.

246 {
247  _mapAttrib[key] = value;
248 }
void XMLCALL xmlParserBase::start_document ( void *  userData)
static

callback usable only with libxml2

Definition at line 54 of file xmlParserBase.cxx.

Referenced by xmlReader::parse().

55 {
56  //DEBTRACE("xmlParserBase::start_document");
57  xmlParserBase *currentParser = static_cast<xmlParserBase *> (userData);
58 }
void XMLCALL xmlParserBase::start_element ( void *  userData,
const xmlChar *  name,
const xmlChar **  p 
)
static

callback called on start of an xml element:

<name> 

Definition at line 72 of file xmlParserBase.cxx.

References incrCount(), onStart(), tochar(), and XML_Char.

Referenced by xmlReader::parse().

75 {
76  //DEBTRACE("xmlParserBase::start_element " << name);
77  cleanGarbage();
78  xmlParserBase *currentParser = static_cast<xmlParserBase *> (userData);
79  const XML_Char *aName = tochar(name);
80  currentParser->incrCount(aName);
81  currentParser->onStart(aName, p);
82 }
void xmlParserBase::stopParse ( std::string  what)
protectedvirtual

Throws an exception.

Definition at line 325 of file xmlParserBase.cxx.

Referenced by YACS::ENGINE::sampleParser::onEnd(), and YACS::ENGINE::sampleParser::onStart().

326 {
327  xmlStopParser(_xmlParser);
328 }
void XMLCALL xmlParserBase::warning ( void *  userData,
const char *  fmt,
  ... 
)
static

callback usable only with libxml2

Definition at line 133 of file xmlParserBase.cxx.

References DEBTRACE.

Referenced by xmlReader::parse().

135 {
136  DEBTRACE("xmlParserBase::warning");
137  xmlParserBase *currentParser = static_cast<xmlParserBase *> (userData);
138  va_list args;
139  va_start(args, fmt);
140  string format = "%s";
141  if (format == fmt)
142  {
143  char* parv;
144  parv = va_arg(args, char*);
145  cerr << parv ;
146  }
147  else cerr << __FILE__ << " [" << __LINE__ << "] : "
148  << "error format not taken into account: " << fmt << endl;
149  va_end(args);
150 }
void xmlParserBase::XML_SetUserData ( _xmlParserCtxt *  ctxt,
xmlParserBase parser 
)
static

Definition at line 37 of file xmlParserBase.cxx.

Referenced by YACS::ENGINE::sampleParser::onStart().

39 {
40  ctxt->userData = parser;
41 }

Member Data Documentation

std::string xmlParserBase::_data
protected
xmlParserBase* xmlParserBase::_father
protected

Definition at line 107 of file xmlParserBase.hxx.

Referenced by YACS::ENGINE::sampleParser::init().

std::list< xmlParserBase * > xmlParserBase::_garbage
staticprotected

Definition at line 105 of file xmlParserBase.hxx.

Referenced by getGarbageSize().

std::map<std::string, std::string> xmlParserBase::_mapAttrib
protected

Definition at line 104 of file xmlParserBase.hxx.

Referenced by YACS::ENGINE::sampleParser::onEnd().

std::stack< xmlParserBase * > xmlParserBase::_stackParser
static

Definition at line 91 of file xmlParserBase.hxx.

Referenced by YACS::ENGINE::sampleParser::onStart(), and xmlReader::parse().

_xmlParserCtxt * xmlParserBase::_xmlParser
static

Definition at line 87 of file xmlParserBase.hxx.

Referenced by YACS::ENGINE::sampleParser::onStart(), and xmlReader::parse().

std::map< std::string, int > xmlParserBase::counts

Definition at line 85 of file xmlParserBase.hxx.


The documentation for this class was generated from the following files: