1 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabaseStandardXMLParser.hh"
2 #include <xercesc/sax2/SAX2XMLReader.hpp>
3 #include <xercesc/sax2/XMLReaderFactory.hpp>
4 #include "xercesc/sax2/DefaultHandler.hpp"
5 #include "xercesc/sax2/Attributes.hpp"
10 ConfigurationDatabaseStandardXMLParser::ConfigurationDatabaseStandardXMLParser() : m_parser(0) {
12 #include <xercesc/framework/MemBufInputSource.hpp>
13 XERCES_CPP_NAMESPACE_USE
64 virtual void startElement (
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname,
const Attributes &attrs)
override;
65 virtual void endElement (
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname)
override;
66 virtual void characters(
const XMLCh*
const chars,
const unsigned int length)
override;
70 if (val==0)
return false;
82 std::list<ConfigurationDatabaseStandardXMLParser::Item>&
m_items;
90 if (!XMLString::compareIString(localname,
xc_header[
i]))
return true;
103 }
else if (!XMLString::compareIString(localname,
xc_Parameter)) {
111 }
else if (!XMLString::compareIString(localname,
xc_Data)) {
124 for (
unsigned int jj=0;
jj<attrs.getLength();
jj++) {
125 if (!XMLString::compareIString(
xc_elements,attrs.getValue(
jj)) ||
147 if (entry.empty())
continue;
152 if (!entry.empty())
m_workitem.items.push_back(entry);
165 while (offset<length) {
167 for (i=0; i<length-offset && i<255; i++)
m_workx[i]=chars[i+offset];
177 std::list<Item> theItems;
182 m_parser=xercesc::XMLReaderFactory::createXMLReader();
185 MemBufInputSource
src((
const unsigned char*)xmlDocument.c_str(), xmlDocument.length(),
"hcal::ConfigurationDatabase");
186 m_parser->setContentHandler(&handler);
187 m_parser->parse(
src);
189 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,ex.what());
191 if (theItems.size()==0) {
192 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
"No data found");
193 }
else if (theItems.size()>1) {
194 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
"Multiple items found");
197 items=theItems.front().items;
198 encoding=theItems.front().encoding;
204 void ConfigurationDatabaseStandardXMLParser::parseMultiple(
const std::string& xmlDocument, std::list<Item>&
items)
throw (hcal::exception::ConfigurationDatabaseException) {
210 m_parser=xercesc::XMLReaderFactory::createXMLReader();
213 MemBufInputSource
src((
const unsigned char*)xmlDocument.c_str(), xmlDocument.length(),
"hcal::ConfigurationDatabase");
214 m_parser->setContentHandler(&handler);
215 m_parser->parse(
src);
217 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,ex.what());
222 std::vector<unsigned int>
values;
224 if (encoding==
"hex") strtol_base=16;
225 else if (encoding==
"dec") strtol_base=10;
228 for (
unsigned int j=0;
j<
items.size();
j++)
229 values.push_back(strtol(
items[
j].c_str(),0,strtol_base));
bool cvt2String(const XMLCh *val, std::string &ou)
Evaluator * parse(const T &text)
static const int ITEMELEMENTNAMES
ConfigurationDatabaseStandardXMLParser::Item m_workitem
virtual void ignorableWhitespace(const XMLCh *chars, const unsigned int length) override
enum ConfigurationDBHandler::@66 m_mode
XMLCh * xc_header[ITEMELEMENTNAMES]
XMLCh * transcode(const T &fInput)
std::list< ConfigurationDatabaseStandardXMLParser::Item > & m_items
bool isItemElement(const XMLCh *const localname)
virtual ~ConfigurationDBHandler()
virtual void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs) override
ConfigurationDBHandler(std::list< ConfigurationDatabaseStandardXMLParser::Item > &items)
virtual void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname) override
virtual void characters(const XMLCh *const chars, const unsigned int length) override