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 
13 { parent_.emplace_back(NodeName("TinyDom")); }
14 
16 { }
17 
18 const TinyDom & SaxToDom::dom() const
19 {
20  return dom_;
21 }
22 
23 void SaxToDom::startElement( const XMLCh* const uri,
24  const XMLCh* const name,
25  const XMLCh* const qname,
26  const Attributes& atts)
27 {
28  char * strx = XMLString::transcode(name); // element-name
29  NodeName nm(strx); // as a temp.string
30 
31  AttList al; // map of attributes -> values
32  for (unsigned int i = 0; i < atts.getLength(); ++i) {
33  char* aname = XMLString::transcode(atts.getLocalName(i));
34  char* value = XMLString::transcode(atts.getValue(i));
35  // fill the tiny-dom-attribute-list (i.e. the map)
36  al[NodeName(aname)]=NodeName(value);
37 
38  XMLString::release(&aname);
39  XMLString::release(&value);
40  }
41  // add the new element to the dom-tree
42  dom_.addEdge(parent_.back(), nm , al);
43 
44  // set the parent_ to the actual node
45  parent_.emplace_back(nm);
46  XMLString::release(&strx);
47 }
48 
49 void SaxToDom::endElement(const XMLCh* const uri,
50  const XMLCh* const name,
51  const XMLCh* const qname)
52 {
53  parent_.pop_back();
54 }
55 
56 // error handling
58 {
59  char* id = XMLString::transcode(e.getSystemId());
60  char* message = XMLString::transcode(e.getMessage());
61  cerr << "\nError at file " << id
62  << ", line " << e.getLineNumber()
63  << ", char " << e.getColumnNumber()
64  << "\n Message: " << message << endl;
65  XMLString::release(&id);
66  XMLString::release(&message);
67 }
std::map< AttName, AttValue > AttList
Definition: TinyDom.h:17
TagName NodeName
Definition: TinyDom.h:14
XERCES_CPP_NAMESPACE::SAXParseException SAXParseException
Definition: SaxToDom.h:21
Definition: TagName.h:9
void endElement(const XMLCh *uri, const XMLCh *name, const XMLCh *qname) override
Definition: SaxToDom.cc:49
XERCES_CPP_NAMESPACE::Attributes Attributes
Definition: SaxToDom.h:20
Definition: value.py:1
void error(const SAXParseException &e) override
Definition: SaxToDom.cc:57
SaxToDom()
Definition: SaxToDom.cc:12
~SaxToDom() override
Definition: SaxToDom.cc:15
void startElement(const XMLCh *uri, const XMLCh *localname, const XMLCh *qname, const Attributes &attrs) override
Definition: SaxToDom.cc:23
const TinyDom & dom() const
Definition: SaxToDom.cc:18