Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:35

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