CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SaxToDom.cc
Go to the documentation of this file.
3 
4 #include <xercesc/sax2/Attributes.hpp>
5 #include <xercesc/sax/SAXParseException.hpp>
6 #include <xercesc/sax/SAXException.hpp>
7 
8 #include <iostream>
9 //#include <string>
10 
11 using namespace std;
12 
14 { parent_.push_back(NodeName("TinyDom")); }
15 
17 { }
18 
19 
20 const TinyDom & SaxToDom::dom() const
21 {
22  return dom_;
23 }
24 
25 
26 void SaxToDom::startElement( const XMLCh* const uri,
27  const XMLCh* const name,
28  const XMLCh* const qname,
29  const Attributes& atts)
30 {
31  StrX strx(name); // element-name
32  NodeName nm(string(strx.localForm())); // as a temp.string
33  //parent_.push_back(nm);
34  AttList al; // map of attributes -> values
35  for (unsigned int i = 0; i < atts.getLength(); ++i) {
36  const XMLCh* aname = atts.getLocalName(i);
37  const XMLCh* value = atts.getValue(i);
38  // fill the tiny-dom-attribute-list (i.e. the map)
39  al[NodeName((StrX(aname).localForm()))]=NodeName(StrX(value).localForm());
40  //cout << " att=" << StrX(aname) << " val=" << StrX(value) << endl;
41  }
42  // add the new element to the dom-tree
43  dom_.addEdge(parent_.back(), nm , al);
44  //cout << "add from=" << parent_.back().str() << " to=" << nm.str() << endl;
45  // set the parent_ to the actual node
46  parent_.push_back(nm);
47 }
48 
49 
50 void SaxToDom::endElement(const XMLCh* const uri,
51  const XMLCh* const name,
52  const XMLCh* const qname)
53 {
54  parent_.pop_back();
55 }
56 
57 // error handling
59 {
60  cerr << "\nError at file " << StrX(e.getSystemId())
61  << ", line " << e.getLineNumber()
62  << ", char " << e.getColumnNumber()
63  << "\n Message: " << StrX(e.getMessage()) << endl;
64 }
65 
66 
XERCES_CPP_NAMESPACE::Attributes Attributes
Definition: SaxToDom.h:18
int i
Definition: DBlmapReader.cc:9
void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs)
Definition: SaxToDom.cc:26
Definition: TagName.h:9
void endElement(const XMLCh *const uri, const XMLCh *const name, const XMLCh *const qname)
Definition: SaxToDom.cc:50
const char * localForm() const
Definition: StrX.h:66
void error(const SAXParseException &e)
Definition: SaxToDom.cc:58
SaxToDom()
Definition: SaxToDom.cc:13
Definition: StrX.h:32
TagName NodeName
Definition: TinyDom.h:13
std::map< AttName, AttValue > AttList
Definition: TinyDom.h:16
~SaxToDom()
Definition: SaxToDom.cc:16
const TinyDom & dom() const
Definition: SaxToDom.cc:20
XERCES_CPP_NAMESPACE::SAXParseException SAXParseException
Definition: SaxToDom.h:19