CMS 3D CMS Logo

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