CMS 3D CMS Logo

SaxToDom2.cc
Go to the documentation of this file.
3 #include <xercesc/util/XMLString.hpp>
4 
5 #include <iostream>
6 #include <map>
7 #include <string>
8 
9 using namespace std;
10 
12 
14  AttList2 al;
15  al[TagName("name")] = TagName("myTinyDomTest");
16  Node2 nm(TagName("TinyDom2"), al);
17  parent_.emplace_back(nm);
18 }
19 
21 
22 const TinyDom2& SaxToDom2::dom() const { return dom_; }
23 
24 void SaxToDom2::startElement(const XMLCh* const uri,
25  const XMLCh* const name,
26  const XMLCh* const qname,
27  const Attributes& atts) {
28  char* strx = XMLString::transcode(name); // element-name
29  AttList2 al;
30 
31  for (unsigned int i = 0; i < atts.getLength(); ++i) {
32  char* aname = XMLString::transcode(atts.getLocalName(i));
33  char* value = XMLString::transcode(atts.getValue(i));
34  al[TagName(aname)] = TagName(value);
35  XMLString::release(&aname);
37  }
38 
39  // add the new element to the dom-tree
40  Node2 nm(TagName(strx), al);
41  Node2 par = parent_.back();
42  dom_.addEdge(par, nm, AnotherDummy2());
43 
44  parent_.emplace_back(nm);
45  XMLString::release(&strx);
46 }
47 
48 void SaxToDom2::endElement(const XMLCh* const uri, const XMLCh* const name, const XMLCh* const qname) {
49  parent_.pop_back();
50 }
51 
52 // error handling
54  char* id = XMLString::transcode(e.getSystemId());
55  char* message = XMLString::transcode(e.getMessage());
56  cerr << "\nError at file " << id << ", line " << e.getLineNumber() << ", char " << e.getColumnNumber()
57  << "\n Message: " << message << endl;
58  XMLString::release(&id);
59  XMLString::release(&message);
60 }
void error(const SAXParseException &e) override
Definition: SaxToDom2.cc:53
Definition: TagName.h:9
~SaxToDom2() override
Definition: SaxToDom2.cc:20
std::map< TagName, TagName > AttList2
Definition: TinyDom2.h:15
Definition: value.py:1
XERCES_CPP_NAMESPACE::SAXParseException SAXParseException
Definition: SaxToDom2.h:22
std::pair< TagName, AttList2 > Node2
Definition: TinyDom2.h:16
void startElement(const XMLCh *uri, const XMLCh *localname, const XMLCh *qname, const Attributes &attrs) override
Definition: SaxToDom2.cc:24
const TinyDom2 & dom() const
Definition: SaxToDom2.cc:22
XERCES_CPP_NAMESPACE::Attributes Attributes
Definition: SaxToDom2.h:21
void endElement(const XMLCh *uri, const XMLCh *name, const XMLCh *qname) override
Definition: SaxToDom2.cc:48