CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DetectorDescription/RegressionTest/src/SaxToDom.cc

Go to the documentation of this file.
00001 #include "DetectorDescription/RegressionTest/src/SaxToDom.h"
00002 #include "DetectorDescription/RegressionTest/src/StrX.h"
00003 
00004 #include <xercesc/sax2/Attributes.hpp>
00005 #include <xercesc/sax/SAXParseException.hpp>
00006 #include <xercesc/sax/SAXException.hpp>
00007 
00008 #include <iostream>
00009 //#include <string>
00010 
00011 using namespace std;
00012 
00013 SaxToDom::SaxToDom() 
00014 { parent_.push_back(NodeName("TinyDom")); }
00015 
00016 SaxToDom::~SaxToDom() 
00017 { }
00018 
00019 
00020 const TinyDom & SaxToDom::dom() const
00021 {
00022    return dom_;
00023 }
00024 
00025 
00026 void SaxToDom::startElement( const XMLCh* const uri, 
00027                             const XMLCh* const name, 
00028                                const XMLCh* const qname, 
00029                                const Attributes& atts)
00030 {
00031   StrX strx(name); // element-name
00032   NodeName nm(string(strx.localForm())); // as a temp.string
00033   //parent_.push_back(nm);
00034   AttList al; // map of attributes -> values
00035   for (unsigned int i = 0; i < atts.getLength(); ++i) {
00036     const XMLCh* aname = atts.getLocalName(i);
00037     const XMLCh* value = atts.getValue(i);
00038     // fill the tiny-dom-attribute-list (i.e. the map)
00039     al[NodeName((StrX(aname).localForm()))]=NodeName(StrX(value).localForm());
00040     //cout << "  att=" << StrX(aname) << " val=" << StrX(value) << endl;
00041   }  
00042   // add the new element to the dom-tree
00043   dom_.addEdge(parent_.back(), nm , al);
00044   //cout << "add from=" << parent_.back().str() << " to=" << nm.str() << endl;
00045   // set the parent_ to the actual node
00046   parent_.push_back(nm);
00047 }
00048 
00049 
00050 void SaxToDom::endElement(const XMLCh* const uri, 
00051                             const XMLCh* const name, 
00052                                const XMLCh* const qname)
00053 {
00054   parent_.pop_back();
00055 }
00056 
00057 // error handling
00058 void SaxToDom::error(const SAXParseException& e)
00059 {
00060     cerr << "\nError at file " << StrX(e.getSystemId())
00061                  << ", line " << e.getLineNumber()
00062                  << ", char " << e.getColumnNumber()
00063          << "\n  Message: " << StrX(e.getMessage()) << endl;
00064 }
00065 
00066