Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:08:22

0001 #include "DetectorDescription/RegressionTest/src/SaxToDom2.h"
0002 #include "DetectorDescription/RegressionTest/src/TagName.h"
0003 #include <xercesc/util/XMLString.hpp>
0004 
0005 #include <iostream>
0006 #include <map>
0007 #include <string>
0008 
0009 using namespace std;
0010 
0011 XERCES_CPP_NAMESPACE_USE
0012 
0013 SaxToDom2::SaxToDom2() {
0014   AttList2 al;
0015   al[TagName("name")] = TagName("myTinyDomTest");
0016   Node2 nm(TagName("TinyDom2"), al);
0017   parent_.emplace_back(nm);
0018 }
0019 
0020 SaxToDom2::~SaxToDom2() {}
0021 
0022 const TinyDom2& SaxToDom2::dom() const { return dom_; }
0023 
0024 void SaxToDom2::startElement(const XMLCh* const uri,
0025                              const XMLCh* const name,
0026                              const XMLCh* const qname,
0027                              const Attributes& atts) {
0028   char* strx = XMLString::transcode(name);  // element-name
0029   AttList2 al;
0030 
0031   for (unsigned int i = 0; i < atts.getLength(); ++i) {
0032     char* aname = XMLString::transcode(atts.getLocalName(i));
0033     char* value = XMLString::transcode(atts.getValue(i));
0034     al[TagName(aname)] = TagName(value);
0035     XMLString::release(&aname);
0036     XMLString::release(&value);
0037   }
0038 
0039   // add the new element to the dom-tree
0040   Node2 nm(TagName(strx), al);
0041   Node2 par = parent_.back();
0042   dom_.addEdge(par, nm, AnotherDummy2());
0043 
0044   parent_.emplace_back(nm);
0045   XMLString::release(&strx);
0046 }
0047 
0048 void SaxToDom2::endElement(const XMLCh* const uri, const XMLCh* const name, const XMLCh* const qname) {
0049   parent_.pop_back();
0050 }
0051 
0052 // error handling
0053 void SaxToDom2::error(const SAXParseException& e) {
0054   char* id = XMLString::transcode(e.getSystemId());
0055   char* message = XMLString::transcode(e.getMessage());
0056   cerr << "\nError at file " << id << ", line " << e.getLineNumber() << ", char " << e.getColumnNumber()
0057        << "\n  Message: " << message << endl;
0058   XMLString::release(&id);
0059   XMLString::release(&message);
0060 }