//-------------------------------------------------------------------------- // // Environment: // This software is part of the EvtGen package developed jointly // for the BaBar and CLEO collaborations. If you use all or part // of it, please give an appropriate acknowledgement. // // Copyright Information: See EvtGen/COPYRIGHT // Copyright (C) 1998 Caltech, UCSB // // Module: EvtParserXml.cc // // Description: Reading the decay XML file. // // Modification history: // // DCC 24 October, 2011 Module created // //------------------------------------------------------------------------ // #include "EvtGenBase/EvtPatches.hh" #include "EvtGenBase/EvtPatches.hh" #include #include #include #include #include #include "EvtGenBase/EvtParserXml.hh" #include "EvtGenBase/EvtReport.hh" using namespace std; EvtParserXml::EvtParserXml(){ _line = ""; _lineNo=0; _tag = ""; _tagTitle = ""; } EvtParserXml::~EvtParserXml(){ } bool EvtParserXml::open(std::string filename){ if(!expandEnvVars(filename)) { report(ERROR,"EvtGen") << "Error while expanding environment variables in file name '"<", startTag) == std::string::npos) { std::string addLine; if(!std::getline(_fin, addLine)) return false; _lineNo++; _line += " "; _line += addLine; } endTag = _line.find("?>", startTag); _line = _line.substr(endTag + 2); return readNextTag(); } else if(_line[startTag+1] == '!') { //XML comment tag - ignore then read the next tag while(_line.find("-->", startTag) == std::string::npos) { std::string addLine; if(!std::getline(_fin, addLine)) return false; _lineNo++; _line += " "; _line += addLine; } endTag = _line.find("-->", startTag); _line = _line.substr(endTag + 3); _tagTitle = ""; _tag = ""; return readNextTag(); } else { //parsable while(_line.find(">", startTag) == std::string::npos) {//find end of a tag std::string addLine; if(!std::getline(_fin, addLine)) return false; _lineNo++; _line += " "; _line += addLine; } endTag = _line.find(">", startTag); _inLineTag = false; if(_line.find("/>", startTag) < endTag) { endTag--; _inLineTag = true; } if(_line.find(" ", startTag) != std::string::npos && _line.find(" ", startTag) < endTag) {//find end of the first word in the tag endTagTitle = _line.find(" ", startTag); } else { endTagTitle = endTag; } _tagTitle = _line.substr(startTag + 1, endTagTitle - startTag - 1); _tag = _line.substr(startTag + 1, endTag - startTag - 1); //now we have the tag lets remove it from the line if(_inLineTag) { _line = _line.substr(endTag+2); } else { _line = _line.substr(endTag+1); } return true; } } std::string EvtParserXml::getParentTagTitle() { if(_tagTree.empty()) return ""; else return _tagTree.back(); } std::string EvtParserXml::readAttribute(std::string attribute, std::string defaultValue) { std::string whitespace = " \t\n\v\f\r"; for(unsigned int i=0; i='0' && c<='9') return true; if(c>='A' && c<='Z') return true; if(c>='a' && c<='z') return true; if(c=='_') return true; return false; }