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