CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DetectorDescription/RegressionTest/src/SaxToDom2.cc

Go to the documentation of this file.
00001 #include "DetectorDescription/RegressionTest/src/SaxToDom2.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 SaxToDom2::SaxToDom2() 
00014 { 
00015   AttList2 al;
00016   al [ TagName("name") ] = TagName("myTinyDomTest");
00017   Node2 nm(TagName("TinyDom2"), al);
00018   parent_.push_back( nm );
00019 }
00020 
00021 SaxToDom2::~SaxToDom2() 
00022 { }
00023 
00024 
00025 const TinyDom2 & SaxToDom2::dom() const
00026 {
00027    return dom_;
00028 }
00029 
00030 
00031 void SaxToDom2::startElement( const XMLCh* const uri, 
00032                             const XMLCh* const name, 
00033                                const XMLCh* const qname, 
00034                                const Attributes& atts)
00035 {
00036   StrX strx(name); // element-name
00037   AttList2 al;
00038 
00039   for (unsigned int i = 0; i < atts.getLength(); ++i)
00040     {
00041       const XMLCh* aname = atts.getLocalName(i);
00042       const XMLCh* value = atts.getValue(i);
00043       al[TagName((StrX(aname).localForm()))]=TagName(StrX(value).localForm());
00044     }
00045 
00046   // add the new element to the dom-tree
00047   Node2 nm(TagName(strx.localForm()) , al);
00048   Node2 par = parent_.back();
00049   dom_.addEdge(par, nm, AnotherDummy2());
00050 
00051   parent_.push_back(nm);
00052 }
00053 
00054 
00055 void SaxToDom2::endElement(const XMLCh* const uri, 
00056                             const XMLCh* const name, 
00057                                const XMLCh* const qname)
00058 {
00059   parent_.pop_back();
00060 }
00061 
00062 // error handling
00063 void SaxToDom2::error(const SAXParseException& e)
00064 {
00065     cerr << "\nError at file " << StrX(e.getSystemId())
00066                  << ", line " << e.getLineNumber()
00067                  << ", char " << e.getColumnNumber()
00068          << "\n  Message: " << StrX(e.getMessage()) << endl;
00069 }
00070 
00071