10 #include <xercesc/dom/DOMDocument.hpp>
11 #include <xercesc/dom/DOMNodeList.hpp>
24 }
catch( xercesc::XMLException&
e ){
26 char*
message = xercesc::XMLString::transcode( e.getMessage() ) ;
28 std::cerr <<
"XML toolkit initialization error: " << message << std::endl;
37 parser_ =
new xercesc::XercesDOMParser();
48 }
catch ( xercesc::XMLException&
e ){
49 char*
message = xercesc::XMLString::transcode( e.getMessage() );
50 std::cerr <<
"XML toolkit teardown error: " << message << std::endl;
65 if( xercesc::XMLString::equals(
tags_->
TAG_ME, element->getTagName() ) ) {
74 xercesc::DOMNodeList* d1Nodes = element->getElementsByTagName(
tags_->
TAG_1D );
75 const XMLSize_t d1Count = d1Nodes->getLength();
77 for( XMLSize_t d1Index = 0; d1Index < d1Count; ++d1Index ){
79 xercesc::DOMNode* d1Node = d1Nodes->item( d1Index ) ;
81 xercesc::DOMElement* d1Element =
dynamic_cast< xercesc::DOMElement*
>( d1Node ) ;
83 const XMLCh* d1titleXMLCh = d1Element->getAttribute(
tags_->
ATTR_TITLE ) ;
84 c = xercesc::XMLString::transcode( d1titleXMLCh );
90 const XMLCh* d1xbinsXMLCh = d1Element->getAttribute(
tags_->
ATTR_XBINS ) ;
91 c = xercesc::XMLString::transcode( d1xbinsXMLCh );
92 s.clear(); s.str( c );
96 const XMLCh* d1xfromXMLCh = d1Element->getAttribute(
tags_->
ATTR_XFROM ) ;
97 c = xercesc::XMLString::transcode( d1xfromXMLCh );
98 s.clear(); s.str( c );
102 const XMLCh* d1xtoXMLCh = d1Element->getAttribute(
tags_->
ATTR_XTO ) ;
103 c = xercesc::XMLString::transcode( d1xtoXMLCh );
104 s.clear(); s.str( c );
108 const XMLCh* d1ncycleXMLCh = d1Element->getAttribute(
tags_->
ATTR_NCYCLE ) ;
109 c = xercesc::XMLString::transcode( d1ncycleXMLCh );
110 s.clear(); s.str( c );
114 const XMLCh* d1loopXMLCh = d1Element->getAttribute(
tags_->
ATTR_LOOP ) ;
115 c = xercesc::XMLString::transcode( d1loopXMLCh );
116 s.clear(); s.str( c );
129 xercesc::DOMNodeList* d2Nodes = element->getElementsByTagName(
tags_->
TAG_2D );
130 const XMLSize_t d2Count = d2Nodes->getLength();
132 for( XMLSize_t d2Index = 0; d2Index < d2Count; ++d2Index ){
134 xercesc::DOMNode* d2Node = d2Nodes->item( d2Index ) ;
136 xercesc::DOMElement* d2Element =
dynamic_cast< xercesc::DOMElement*
>( d2Node ) ;
138 const XMLCh* d2titleXMLCh = d2Element->getAttribute(
tags_->
ATTR_TITLE ) ;
139 c = xercesc::XMLString::transcode( d2titleXMLCh );
145 const XMLCh* d2xbinsXMLCh = d2Element->getAttribute(
tags_->
ATTR_XBINS ) ;
146 c = xercesc::XMLString::transcode( d2xbinsXMLCh );
147 s.clear(); s.str( c );
151 const XMLCh* d2xfromXMLCh = d2Element->getAttribute(
tags_->
ATTR_XFROM ) ;
152 c = xercesc::XMLString::transcode( d2xfromXMLCh );
153 s.clear(); s.str( c );
157 const XMLCh* d2xtoXMLCh = d2Element->getAttribute(
tags_->
ATTR_XTO ) ;
158 c = xercesc::XMLString::transcode( d2xtoXMLCh );
159 s.clear(); s.str( c );
163 const XMLCh* d2ybinsXMLCh = d2Element->getAttribute(
tags_->
ATTR_YBINS ) ;
164 c = xercesc::XMLString::transcode( d2ybinsXMLCh );
165 s.clear(); s.str( c );
169 const XMLCh* d2yfromXMLCh = d2Element->getAttribute(
tags_->
ATTR_YFROM ) ;
170 c = xercesc::XMLString::transcode( d2yfromXMLCh );
171 s.clear(); s.str( c );
175 const XMLCh* d2ytoXMLCh = d2Element->getAttribute(
tags_->
ATTR_YTO ) ;
176 c = xercesc::XMLString::transcode( d2ytoXMLCh );
177 s.clear(); s.str( c );
181 const XMLCh* d2ncycleXMLCh = d2Element->getAttribute(
tags_->
ATTR_NCYCLE ) ;
182 c = xercesc::XMLString::transcode( d2ncycleXMLCh );
183 s.clear(); s.str( c );
187 const XMLCh* d2loopXMLCh = d2Element->getAttribute(
tags_->
ATTR_LOOP ) ;
188 c = xercesc::XMLString::transcode( d2loopXMLCh );
189 s.clear(); s.str( c );
199 xercesc::DOMNodeList* tpNodes = element->getElementsByTagName(
tags_->
TAG_TPROFILE );
200 const XMLSize_t tpCount = tpNodes->getLength();
202 for( XMLSize_t tpIndex = 0; tpIndex < tpCount; ++tpIndex ){
204 xercesc::DOMNode* tpNode = tpNodes->item( tpIndex ) ;
206 xercesc::DOMElement* tpElement =
dynamic_cast< xercesc::DOMElement*
>( tpNode ) ;
208 const XMLCh* tptitleXMLCh = tpElement->getAttribute(
tags_->
ATTR_TITLE ) ;
209 c = xercesc::XMLString::transcode( tptitleXMLCh );
210 me.
type =
"tprofile";
215 const XMLCh* tpxbinsXMLCh = tpElement->getAttribute(
tags_->
ATTR_XBINS ) ;
216 c = xercesc::XMLString::transcode( tpxbinsXMLCh );
217 s.clear(); s.str( c );
221 const XMLCh* tpxfromXMLCh = tpElement->getAttribute(
tags_->
ATTR_XFROM ) ;
222 c = xercesc::XMLString::transcode( tpxfromXMLCh );
223 s.clear(); s.str( c );
227 const XMLCh* tpxtoXMLCh = tpElement->getAttribute(
tags_->
ATTR_XTO ) ;
228 c = xercesc::XMLString::transcode( tpxtoXMLCh );
229 s.clear(); s.str( c );
233 const XMLCh* tpybinsXMLCh = tpElement->getAttribute(
tags_->
ATTR_YBINS ) ;
234 c = xercesc::XMLString::transcode( tpybinsXMLCh );
235 s.clear(); s.str( c );
239 const XMLCh* tpyfromXMLCh = tpElement->getAttribute(
tags_->
ATTR_YFROM ) ;
240 c = xercesc::XMLString::transcode( tpyfromXMLCh );
241 s.clear(); s.str( c );
245 const XMLCh* tpytoXMLCh = tpElement->getAttribute(
tags_->
ATTR_YTO ) ;
246 c = xercesc::XMLString::transcode( tpytoXMLCh );
247 s.clear(); s.str( c );
251 const XMLCh* tpncycleXMLCh = tpElement->getAttribute(
tags_->
ATTR_NCYCLE ) ;
252 c = xercesc::XMLString::transcode( tpncycleXMLCh );
253 s.clear(); s.str( c );
257 const XMLCh* tploopXMLCh = tpElement->getAttribute(
tags_->
ATTR_LOOP ) ;
258 c = xercesc::XMLString::transcode( tploopXMLCh );
259 s.clear(); s.str( c );
270 const XMLSize_t tp2dCount = tp2dNodes->getLength();
272 for( XMLSize_t tp2dIndex = 0; tp2dIndex < tp2dCount; ++tp2dIndex ){
274 xercesc::DOMNode* tp2dNode = tp2dNodes->item( tp2dIndex ) ;
276 xercesc::DOMElement* tp2dElement =
dynamic_cast< xercesc::DOMElement*
>( tp2dNode ) ;
278 const XMLCh* tp2dtitleXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_TITLE ) ;
279 c = xercesc::XMLString::transcode( tp2dtitleXMLCh );
280 me.
type =
"tprofile2d";
285 const XMLCh* tp2dxbinsXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_XBINS ) ;
286 c = xercesc::XMLString::transcode( tp2dxbinsXMLCh );
287 s.clear(); s.str( c );
291 const XMLCh* tp2dxfromXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_XFROM ) ;
292 c = xercesc::XMLString::transcode( tp2dxfromXMLCh );
293 s.clear(); s.str( c );
297 const XMLCh* tp2dxtoXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_XTO ) ;
298 c = xercesc::XMLString::transcode( tp2dxtoXMLCh );
299 s.clear(); s.str( c );
303 const XMLCh* tp2dybinsXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_YBINS ) ;
304 c = xercesc::XMLString::transcode( tp2dybinsXMLCh );
305 s.clear(); s.str( c );
309 const XMLCh* tp2dyfromXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_YFROM ) ;
310 c = xercesc::XMLString::transcode( tp2dyfromXMLCh );
311 s.clear(); s.str( c );
315 const XMLCh* tp2dytoXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_YTO ) ;
316 c = xercesc::XMLString::transcode( tp2dytoXMLCh );
317 s.clear(); s.str( c );
321 const XMLCh* tp2dzbinsXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_ZBINS ) ;
322 c = xercesc::XMLString::transcode( tp2dzbinsXMLCh );
323 s.clear(); s.str( c );
327 const XMLCh* tp2dzfromXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_ZFROM ) ;
328 c = xercesc::XMLString::transcode( tp2dzfromXMLCh );
329 s.clear(); s.str( c );
333 const XMLCh* tp2dztoXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_ZTO ) ;
334 c = xercesc::XMLString::transcode( tp2dztoXMLCh );
335 s.clear(); s.str( c );
339 const XMLCh* tp2dncycleXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_NCYCLE ) ;
340 c = xercesc::XMLString::transcode( tp2dncycleXMLCh );
341 s.clear(); s.str( c );
345 const XMLCh* tp2dloopXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_LOOP ) ;
346 c = xercesc::XMLString::transcode( tp2dloopXMLCh );
347 s.clear(); s.str( c );
354 xercesc::DOMNodeList* qNodes = element->getElementsByTagName(
tags_->
TAG_QUERY );
355 const XMLSize_t qCount = qNodes->getLength();
357 for( XMLSize_t qIndex = 0; qIndex < qCount; ++qIndex ){
359 xercesc::DOMNode* qNode = qNodes->item( qIndex ) ;
361 xercesc::DOMElement* qElement =
dynamic_cast< xercesc::DOMElement*
>( qNode ) ;
363 const XMLCh* nameXMLCh = qElement->getAttribute(
tags_->
ATTR_NAME ) ;
364 c = xercesc::XMLString::transcode( nameXMLCh );
366 const XMLCh* argXMLCh = qElement->getAttribute(
tags_->
ATTR_ARG ) ;
367 char* d = xercesc::XMLString::transcode( argXMLCh );
369 const XMLCh* aliasXMLCh = qElement->getAttribute(
tags_->
ATTR_ALIAS ) ;
370 char*
e = xercesc::XMLString::transcode( aliasXMLCh );
377 me.
queries.push_back( tmpQuery );
396 parser_->setValidationScheme( xercesc::XercesDOMParser::Val_Never );
397 parser_->setDoNamespaces(
false );
399 parser_->setLoadExternalDTD(
false );
405 xercesc::DOMDocument* xmlDoc =
parser_->getDocument();
407 xercesc::DOMElement* dbe = xmlDoc->getDocumentElement();
410 throw( std::runtime_error(
"empty XML document" ) ) ;
413 if( xercesc::XMLString::equals(
tags_->
TAG_DBE, dbe->getTagName() ) ) {
415 xercesc::DOMNodeList* children = dbe->getChildNodes();
416 const XMLSize_t nodeCount = children->getLength();
418 for( XMLSize_t ix = 0 ; ix < nodeCount ; ++ix ){
419 xercesc::DOMNode* currentNode = children->item( ix );
420 if(
NULL == currentNode ){
425 if( xercesc::DOMNode::ELEMENT_NODE != currentNode->getNodeType() ){
429 xercesc::DOMElement* currentElement =
dynamic_cast< xercesc::DOMElement*
>( currentNode );
436 }
catch( xercesc::XMLException&
e ){
438 char*
message = xercesc::XMLString::transcode( e.getMessage() );
440 std::ostringstream buf ;
441 buf <<
"Error parsing file: " << message << std::endl;
445 throw( std::runtime_error( buf.str() ) );
447 }
catch(
const xercesc::DOMException& e ){
449 char*
message = xercesc::XMLString::transcode( e.getMessage() );
451 std::ostringstream buf;
452 buf <<
"Encountered DOM Exception: " << message << std::endl;
456 throw( std::runtime_error( buf.str() ) );
MonitorXMLParser(const std::string &fromFile)
std::vector< DbQuery > queries
std::vector< DB_ME > DBMonitoringElements_
void handleElement(xercesc::DOMElement *element)
monitor db xml elements parsing tool
xercesc::XercesDOMParser * parser_