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 NodeName
Definition: TinyDom.h:14
XERCES_CPP_NAMESPACE::SAXParseException SAXParseException
Definition: SaxToDom.h:20
Definition: TagName.h:9
void endElement(const XMLCh *uri, const XMLCh *name, const XMLCh *qname) override
Definition: SaxToDom.cc:43
const TinyDom & dom() const
Definition: SaxToDom.cc:16
std::map< AttName, AttValue > AttList
Definition: TinyDom.h:17
XERCES_CPP_NAMESPACE::Attributes Attributes
Definition: SaxToDom.h:19
Definition: value.py:1
void error(const SAXParseException &e) override
Definition: SaxToDom.cc:48
SaxToDom()
Definition: SaxToDom.cc:12
~SaxToDom() override
Definition: SaxToDom.cc:14
void startElement(const XMLCh *uri, const XMLCh *localname, const XMLCh *qname, const Attributes &attrs) override
Definition: SaxToDom.cc:18