CMS 3D CMS Logo

DDLSAX2Handler.h
Go to the documentation of this file.
1 #ifndef DETECTORDESCRIPTION_PARSER_DDLSAX2HANDLER_H
2 #define DETECTORDESCRIPTION_PARSER_DDLSAX2HANDLER_H
3 
4 #include <xercesc/sax2/Attributes.hpp>
5 #include <xercesc/sax2/DefaultHandler.hpp>
6 #include <iostream>
7 #include <string>
8 #include <vector>
9 
11 
27 class DDLSAX2Handler : public XERCES_CPP_NAMESPACE::DefaultHandler
28 {
29  public:
30  typedef XERCES_CPP_NAMESPACE::Attributes Attributes;
31  typedef XERCES_CPP_NAMESPACE::SAXParseException SAXParseException;
32 
35 
37  unsigned int getElementCount() const
38  {
39  return elementCount_;
40  }
42  unsigned int getAttrCount() const
43  {
44  return attrCount_;
45  }
47  unsigned int getCharacterCount() const
48  {
49  return characterCount_;
50  }
52  bool getSawErrors() const
53  {
54  return sawErrors_;
55  }
57  unsigned int getSpaceCount() const
58  {
59  return spaceCount_;
60  }
61 
62  // -----------------------------------------------------------------------
63  // Handlers for the SAX ContentHandler interface
64  // -----------------------------------------------------------------------
65 
66  virtual void startElement(const XMLCh* const uri, const XMLCh* const localname,
67  const XMLCh* const qname, const Attributes& attrs) override;
68  virtual void endElement(const XMLCh* const uri, const XMLCh* const localname,
69  const XMLCh* const qname) override;
70  virtual void characters(const XMLCh* const chars, const XMLSize_t length) override;
71  virtual void comment (const XMLCh *const chars, const XMLSize_t length ) override;
72  virtual void ignorableWhitespace(const XMLCh* const chars, const XMLSize_t length) override;
73  virtual void resetDocument() override;
74 
75  // -----------------------------------------------------------------------
76  // Handlers for the SAX ErrorHandler interface
77  // -----------------------------------------------------------------------
78  virtual void warning(const SAXParseException& exception) override;
79  virtual void error(const SAXParseException& exception) override;
80  virtual void fatalError(const SAXParseException& exception) override;
81  virtual void dumpStats(const std::string& fname);
82 
83  protected:
84 
85  // -----------------------------------------------------------------------
86  // Protected data members
87  //
88  // attrCount_
89  // characterCount_
90  // elementCount_
91  // spaceCount_
92  // These are just counters that are run upwards based on the input
93  // from the document handlers.
94  //
95  // sawErrors
96  // This is set by the error handlers, and is queryable later to
97  // see if any errors occurred.
98  // -----------------------------------------------------------------------
99  XMLSize_t attrCount_;
100  XMLSize_t characterCount_;
101  XMLSize_t elementCount_;
102  XMLSize_t spaceCount_;
104  bool userNS_;
106 
107  public:
113  virtual void setUserNS(bool userns);
114  virtual void setNameSpace(const std::string& nms);
115 };
116 
117 #endif
virtual void error(const SAXParseException &exception) override
virtual void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname) override
unsigned int getAttrCount() const
Get the count of attributes processed so far.
XMLSize_t spaceCount_
virtual void comment(const XMLCh *const chars, const XMLSize_t length) override
XMLSize_t characterCount_
XMLSize_t attrCount_
XMLSize_t elementCount_
virtual void characters(const XMLCh *const chars, const XMLSize_t length) override
virtual void fatalError(const SAXParseException &exception) override
XERCES_CPP_NAMESPACE::SAXParseException SAXParseException
bool getSawErrors() const
Did the XML parser see any errors?
virtual void setUserNS(bool userns)
std::string nmspace_
unsigned int getElementCount() const
Get the count of elements processed so far.
unsigned int getCharacterCount() const
Get the count of characters processed so far.
unsigned int getSpaceCount() const
Get the count of spaces processed so far.
virtual void warning(const SAXParseException &exception) override
virtual void resetDocument() override
string fname
main script
virtual void setNameSpace(const std::string &nms)
DDLSAX2Handler inherits from Xerces C++ DefaultHandler.
virtual void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs) override
virtual void dumpStats(const std::string &fname)
XERCES_CPP_NAMESPACE::Attributes Attributes
virtual void ignorableWhitespace(const XMLCh *const chars, const XMLSize_t length) override