CMS 3D CMS Logo

SaxToDom.cc
Go to the documentation of this file.
2 
3 #include <iostream>
4 #include <map>
5 #include <string>
6 #include <xercesc/util/XMLString.hpp>
7 
8 using namespace std;
9 
11 
12 SaxToDom::SaxToDom() { parent_.emplace_back(NodeName("TinyDom")); }
13 
15 
16 const TinyDom& SaxToDom::dom() const { return dom_; }
17 
18 void SaxToDom::startElement(const XMLCh* const uri,
19  const XMLCh* const name,
20  const XMLCh* const qname,
21  const Attributes& atts) {
22  char* strx = XMLString::transcode(name); // element-name
23  NodeName nm(strx); // as a temp.string
24 
25  AttList al; // map of attributes -> values
26  for (unsigned int i = 0; i < atts.getLength(); ++i) {
27  char* aname = XMLString::transcode(atts.getLocalName(i));
28  char* value = XMLString::transcode(atts.getValue(i));
29  // fill the tiny-dom-attribute-list (i.e. the map)
30  al[NodeName(aname)] = NodeName(value);
31 
32  XMLString::release(&aname);
34  }
35  // add the new element to the dom-tree
36  dom_.addEdge(parent_.back(), nm, al);
37 
38  // set the parent_ to the actual node
39  parent_.emplace_back(nm);
40  XMLString::release(&strx);
41 }
42 
43 void SaxToDom::endElement(const XMLCh* const uri, const XMLCh* const name, const XMLCh* const qname) {
44  parent_.pop_back();
45 }
46 
47 // error handling
49  char* id = XMLString::transcode(e.getSystemId());
50  char* message = XMLString::transcode(e.getMessage());
51  cerr << "\nError at file " << id << ", line " << e.getLineNumber() << ", char " << e.getColumnNumber()
52  << "\n Message: " << message << endl;
53  XMLString::release(&id);
54  XMLString::release(&message);
55 }
TagName
Definition: TagName.h:9
mps_fire.i
i
Definition: mps_fire.py:355
SaxToDom.h
SaxToDom::Attributes
XERCES_CPP_NAMESPACE::Attributes Attributes
Definition: SaxToDom.h:19
XERCES_CPP_NAMESPACE_USE
Definition: XMLConfigWriter.cc:40
SaxToDom::dom
const TinyDom & dom() const
Definition: SaxToDom.cc:16
SaxToDom::SAXParseException
XERCES_CPP_NAMESPACE::SAXParseException SAXParseException
Definition: SaxToDom.h:20
AttList
std::map< AttName, AttValue > AttList
Definition: TinyDom.h:17
SaxToDom::error
void error(const SAXParseException &e) override
Definition: SaxToDom.cc:48
fetchall_from_DQM_v2.release
release
Definition: fetchall_from_DQM_v2.py:92
beam_dqm_sourceclient-live_cfg.cerr
cerr
Definition: beam_dqm_sourceclient-live_cfg.py:17
value
Definition: value.py:1
SaxToDom::endElement
void endElement(const XMLCh *uri, const XMLCh *name, const XMLCh *qname) override
Definition: SaxToDom.cc:43
SaxToDom::SaxToDom
SaxToDom()
Definition: SaxToDom.cc:12
std
Definition: JetResolutionObject.h:76
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
SaxToDom::~SaxToDom
~SaxToDom() override
Definition: SaxToDom.cc:14
math::Graph< NodeName, AttList >
SaxToDom::startElement
void startElement(const XMLCh *uri, const XMLCh *localname, const XMLCh *qname, const Attributes &attrs) override
Definition: SaxToDom.cc:18
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
NodeName
TagName NodeName
Definition: TinyDom.h:14