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 {
15  AttList2 al;
16  al [ TagName("name") ] = TagName("myTinyDomTest");
17  Node2 nm(TagName("TinyDom2"), al);
18  parent_.emplace_back( nm );
19 }
20 
22 { }
23 
24 
25 const TinyDom2 & SaxToDom2::dom() const
26 {
27  return dom_;
28 }
29 
30 
31 void SaxToDom2::startElement( const XMLCh* const uri,
32  const XMLCh* const name,
33  const XMLCh* const qname,
34  const Attributes& atts)
35 {
36  char * strx = XMLString::transcode(name); // element-name
37  AttList2 al;
38 
39  for (unsigned int i = 0; i < atts.getLength(); ++i)
40  {
41  char* aname = XMLString::transcode(atts.getLocalName(i));
42  char* value = XMLString::transcode(atts.getValue(i));
43  al[TagName(aname)]=TagName(value);
44  XMLString::release(&aname);
45  XMLString::release(&value);
46  }
47 
48  // add the new element to the dom-tree
49  Node2 nm(TagName(strx) , al);
50  Node2 par = parent_.back();
51  dom_.addEdge(par, nm, AnotherDummy2());
52 
53  parent_.emplace_back(nm);
54  XMLString::release(&strx);
55 }
56 
57 
58 void SaxToDom2::endElement(const XMLCh* const uri,
59  const XMLCh* const name,
60  const XMLCh* const qname)
61 {
62  parent_.pop_back();
63 }
64 
65 // error handling
67 {
68  char* id = XMLString::transcode(e.getSystemId());
69  char* message = XMLString::transcode(e.getMessage());
70  cerr << "\nError at file " << id
71  << ", line " << e.getLineNumber()
72  << ", char " << e.getColumnNumber()
73  << "\n Message: " << message << endl;
74  XMLString::release(&id);
75  XMLString::release(&message);
76 }
77 
78 
void error(const SAXParseException &e) override
Definition: SaxToDom2.cc:66
Definition: TagName.h:9
~SaxToDom2() override
Definition: SaxToDom2.cc:21
std::map< TagName, TagName > AttList2
Definition: TinyDom2.h:15
Definition: value.py:1
XERCES_CPP_NAMESPACE::SAXParseException SAXParseException
Definition: SaxToDom2.h:24
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:31
XERCES_CPP_NAMESPACE::Attributes Attributes
Definition: SaxToDom2.h:23
const TinyDom2 & dom() const
Definition: SaxToDom2.cc:25
void endElement(const XMLCh *uri, const XMLCh *name, const XMLCh *qname) override
Definition: SaxToDom2.cc:58