11 #include <xercesc/util/PlatformUtils.hpp>
13 #include <xercesc/dom/DOMDocument.hpp>
14 #include <xercesc/dom/DOMNodeList.hpp>
25 xercesc::XMLPlatformUtils::Initialize();
27 }
catch( xercesc::XMLException&
e ){
29 char*
message = xercesc::XMLString::transcode( e.getMessage() ) ;
31 std::cerr <<
"XML toolkit initialization error: " << message << std::endl;
40 parser_ =
new xercesc::XercesDOMParser();
50 xercesc::XMLPlatformUtils::Terminate();
51 }
catch ( xercesc::XMLException&
e ){
52 char*
message = xercesc::XMLString::transcode( e.getMessage() );
53 std::cerr <<
"XML toolkit teardown error: " << message << std::endl;
68 if( xercesc::XMLString::equals(
tags_->
TAG_ME, element->getTagName() ) ) {
77 xercesc::DOMNodeList* d1Nodes = element->getElementsByTagName(
tags_->
TAG_1D );
78 const XMLSize_t d1Count = d1Nodes->getLength();
80 for( XMLSize_t d1Index = 0; d1Index < d1Count; ++d1Index ){
82 xercesc::DOMNode* d1Node = d1Nodes->item( d1Index ) ;
84 xercesc::DOMElement* d1Element =
dynamic_cast< xercesc::DOMElement*
>( d1Node ) ;
86 const XMLCh* d1titleXMLCh = d1Element->getAttribute(
tags_->
ATTR_TITLE ) ;
87 c = xercesc::XMLString::transcode( d1titleXMLCh );
93 const XMLCh* d1xbinsXMLCh = d1Element->getAttribute(
tags_->
ATTR_XBINS ) ;
94 c = xercesc::XMLString::transcode( d1xbinsXMLCh );
95 s.clear(); s.str( c );
99 const XMLCh* d1xfromXMLCh = d1Element->getAttribute(
tags_->
ATTR_XFROM ) ;
100 c = xercesc::XMLString::transcode( d1xfromXMLCh );
101 s.clear(); s.str( c );
105 const XMLCh* d1xtoXMLCh = d1Element->getAttribute(
tags_->
ATTR_XTO ) ;
106 c = xercesc::XMLString::transcode( d1xtoXMLCh );
107 s.clear(); s.str( c );
111 const XMLCh* d1ncycleXMLCh = d1Element->getAttribute(
tags_->
ATTR_NCYCLE ) ;
112 c = xercesc::XMLString::transcode( d1ncycleXMLCh );
113 s.clear(); s.str( c );
117 const XMLCh* d1loopXMLCh = d1Element->getAttribute(
tags_->
ATTR_LOOP ) ;
118 c = xercesc::XMLString::transcode( d1loopXMLCh );
119 s.clear(); s.str( c );
132 xercesc::DOMNodeList* d2Nodes = element->getElementsByTagName(
tags_->
TAG_2D );
133 const XMLSize_t d2Count = d2Nodes->getLength();
135 for( XMLSize_t d2Index = 0; d2Index < d2Count; ++d2Index ){
137 xercesc::DOMNode* d2Node = d2Nodes->item( d2Index ) ;
139 xercesc::DOMElement* d2Element =
dynamic_cast< xercesc::DOMElement*
>( d2Node ) ;
141 const XMLCh* d2titleXMLCh = d2Element->getAttribute(
tags_->
ATTR_TITLE ) ;
142 c = xercesc::XMLString::transcode( d2titleXMLCh );
148 const XMLCh* d2xbinsXMLCh = d2Element->getAttribute(
tags_->
ATTR_XBINS ) ;
149 c = xercesc::XMLString::transcode( d2xbinsXMLCh );
150 s.clear(); s.str( c );
154 const XMLCh* d2xfromXMLCh = d2Element->getAttribute(
tags_->
ATTR_XFROM ) ;
155 c = xercesc::XMLString::transcode( d2xfromXMLCh );
156 s.clear(); s.str( c );
160 const XMLCh* d2xtoXMLCh = d2Element->getAttribute(
tags_->
ATTR_XTO ) ;
161 c = xercesc::XMLString::transcode( d2xtoXMLCh );
162 s.clear(); s.str( c );
166 const XMLCh* d2ybinsXMLCh = d2Element->getAttribute(
tags_->
ATTR_YBINS ) ;
167 c = xercesc::XMLString::transcode( d2ybinsXMLCh );
168 s.clear(); s.str( c );
172 const XMLCh* d2yfromXMLCh = d2Element->getAttribute(
tags_->
ATTR_YFROM ) ;
173 c = xercesc::XMLString::transcode( d2yfromXMLCh );
174 s.clear(); s.str( c );
178 const XMLCh* d2ytoXMLCh = d2Element->getAttribute(
tags_->
ATTR_YTO ) ;
179 c = xercesc::XMLString::transcode( d2ytoXMLCh );
180 s.clear(); s.str( c );
184 const XMLCh* d2ncycleXMLCh = d2Element->getAttribute(
tags_->
ATTR_NCYCLE ) ;
185 c = xercesc::XMLString::transcode( d2ncycleXMLCh );
186 s.clear(); s.str( c );
190 const XMLCh* d2loopXMLCh = d2Element->getAttribute(
tags_->
ATTR_LOOP ) ;
191 c = xercesc::XMLString::transcode( d2loopXMLCh );
192 s.clear(); s.str( c );
202 xercesc::DOMNodeList* tpNodes = element->getElementsByTagName(
tags_->
TAG_TPROFILE );
203 const XMLSize_t tpCount = tpNodes->getLength();
205 for( XMLSize_t tpIndex = 0; tpIndex < tpCount; ++tpIndex ){
207 xercesc::DOMNode* tpNode = tpNodes->item( tpIndex ) ;
209 xercesc::DOMElement* tpElement =
dynamic_cast< xercesc::DOMElement*
>( tpNode ) ;
211 const XMLCh* tptitleXMLCh = tpElement->getAttribute(
tags_->
ATTR_TITLE ) ;
212 c = xercesc::XMLString::transcode( tptitleXMLCh );
213 me.
type =
"tprofile";
218 const XMLCh* tpxbinsXMLCh = tpElement->getAttribute(
tags_->
ATTR_XBINS ) ;
219 c = xercesc::XMLString::transcode( tpxbinsXMLCh );
220 s.clear(); s.str( c );
224 const XMLCh* tpxfromXMLCh = tpElement->getAttribute(
tags_->
ATTR_XFROM ) ;
225 c = xercesc::XMLString::transcode( tpxfromXMLCh );
226 s.clear(); s.str( c );
230 const XMLCh* tpxtoXMLCh = tpElement->getAttribute(
tags_->
ATTR_XTO ) ;
231 c = xercesc::XMLString::transcode( tpxtoXMLCh );
232 s.clear(); s.str( c );
236 const XMLCh* tpybinsXMLCh = tpElement->getAttribute(
tags_->
ATTR_YBINS ) ;
237 c = xercesc::XMLString::transcode( tpybinsXMLCh );
238 s.clear(); s.str( c );
242 const XMLCh* tpyfromXMLCh = tpElement->getAttribute(
tags_->
ATTR_YFROM ) ;
243 c = xercesc::XMLString::transcode( tpyfromXMLCh );
244 s.clear(); s.str( c );
248 const XMLCh* tpytoXMLCh = tpElement->getAttribute(
tags_->
ATTR_YTO ) ;
249 c = xercesc::XMLString::transcode( tpytoXMLCh );
250 s.clear(); s.str( c );
254 const XMLCh* tpncycleXMLCh = tpElement->getAttribute(
tags_->
ATTR_NCYCLE ) ;
255 c = xercesc::XMLString::transcode( tpncycleXMLCh );
256 s.clear(); s.str( c );
260 const XMLCh* tploopXMLCh = tpElement->getAttribute(
tags_->
ATTR_LOOP ) ;
261 c = xercesc::XMLString::transcode( tploopXMLCh );
262 s.clear(); s.str( c );
273 const XMLSize_t tp2dCount = tp2dNodes->getLength();
275 for( XMLSize_t tp2dIndex = 0; tp2dIndex < tp2dCount; ++tp2dIndex ){
277 xercesc::DOMNode* tp2dNode = tp2dNodes->item( tp2dIndex ) ;
279 xercesc::DOMElement* tp2dElement =
dynamic_cast< xercesc::DOMElement*
>( tp2dNode ) ;
281 const XMLCh* tp2dtitleXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_TITLE ) ;
282 c = xercesc::XMLString::transcode( tp2dtitleXMLCh );
283 me.
type =
"tprofile2d";
288 const XMLCh* tp2dxbinsXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_XBINS ) ;
289 c = xercesc::XMLString::transcode( tp2dxbinsXMLCh );
290 s.clear(); s.str( c );
294 const XMLCh* tp2dxfromXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_XFROM ) ;
295 c = xercesc::XMLString::transcode( tp2dxfromXMLCh );
296 s.clear(); s.str( c );
300 const XMLCh* tp2dxtoXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_XTO ) ;
301 c = xercesc::XMLString::transcode( tp2dxtoXMLCh );
302 s.clear(); s.str( c );
306 const XMLCh* tp2dybinsXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_YBINS ) ;
307 c = xercesc::XMLString::transcode( tp2dybinsXMLCh );
308 s.clear(); s.str( c );
312 const XMLCh* tp2dyfromXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_YFROM ) ;
313 c = xercesc::XMLString::transcode( tp2dyfromXMLCh );
314 s.clear(); s.str( c );
318 const XMLCh* tp2dytoXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_YTO ) ;
319 c = xercesc::XMLString::transcode( tp2dytoXMLCh );
320 s.clear(); s.str( c );
324 const XMLCh* tp2dzbinsXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_ZBINS ) ;
325 c = xercesc::XMLString::transcode( tp2dzbinsXMLCh );
326 s.clear(); s.str( c );
330 const XMLCh* tp2dzfromXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_ZFROM ) ;
331 c = xercesc::XMLString::transcode( tp2dzfromXMLCh );
332 s.clear(); s.str( c );
336 const XMLCh* tp2dztoXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_ZTO ) ;
337 c = xercesc::XMLString::transcode( tp2dztoXMLCh );
338 s.clear(); s.str( c );
342 const XMLCh* tp2dncycleXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_NCYCLE ) ;
343 c = xercesc::XMLString::transcode( tp2dncycleXMLCh );
344 s.clear(); s.str( c );
348 const XMLCh* tp2dloopXMLCh = tp2dElement->getAttribute(
tags_->
ATTR_LOOP ) ;
349 c = xercesc::XMLString::transcode( tp2dloopXMLCh );
350 s.clear(); s.str( c );
357 xercesc::DOMNodeList* qNodes = element->getElementsByTagName(
tags_->
TAG_QUERY );
358 const XMLSize_t qCount = qNodes->getLength();
360 for( XMLSize_t qIndex = 0; qIndex < qCount; ++qIndex ){
362 xercesc::DOMNode* qNode = qNodes->item( qIndex ) ;
364 xercesc::DOMElement* qElement =
dynamic_cast< xercesc::DOMElement*
>( qNode ) ;
366 const XMLCh* nameXMLCh = qElement->getAttribute(
tags_->
ATTR_NAME ) ;
367 c = xercesc::XMLString::transcode( nameXMLCh );
369 const XMLCh* argXMLCh = qElement->getAttribute(
tags_->
ATTR_ARG ) ;
370 char* d = xercesc::XMLString::transcode( argXMLCh );
372 const XMLCh* aliasXMLCh = qElement->getAttribute(
tags_->
ATTR_ALIAS ) ;
373 char*
e = xercesc::XMLString::transcode( aliasXMLCh );
380 me.
queries.push_back( tmpQuery );
399 parser_->setValidationScheme( xercesc::XercesDOMParser::Val_Never );
400 parser_->setDoNamespaces(
false );
402 parser_->setLoadExternalDTD(
false );
408 xercesc::DOMDocument* xmlDoc =
parser_->getDocument();
410 xercesc::DOMElement* dbe = xmlDoc->getDocumentElement();
413 throw( std::runtime_error(
"empty XML document" ) ) ;
416 if( xercesc::XMLString::equals(
tags_->
TAG_DBE, dbe->getTagName() ) ) {
418 xercesc::DOMNodeList* children = dbe->getChildNodes();
419 const XMLSize_t nodeCount = children->getLength();
421 for( XMLSize_t ix = 0 ; ix < nodeCount ; ++ix ){
422 xercesc::DOMNode* currentNode = children->item( ix );
423 if(
NULL == currentNode ){
428 if( xercesc::DOMNode::ELEMENT_NODE != currentNode->getNodeType() ){
432 xercesc::DOMElement* currentElement =
dynamic_cast< xercesc::DOMElement*
>( currentNode );
439 }
catch( xercesc::XMLException&
e ){
441 char*
message = xercesc::XMLString::transcode( e.getMessage() );
443 std::ostringstream buf ;
444 buf <<
"Error parsing file: " << message << std::endl;
448 throw( std::runtime_error( buf.str() ) );
450 }
catch(
const xercesc::DOMException& e ){
452 char*
message = xercesc::XMLString::transcode( e.getMessage() );
454 std::ostringstream buf;
455 buf <<
"Encountered DOM Exception: " << message << std::endl;
459 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_