Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26:38

0001 #include <iostream>
0002 #include <vector>
0003 #include <boost/property_tree/ptree.hpp>
0004 #include <boost/property_tree/xml_parser.hpp>
0005 struct Connection{
0006   std::string name;
0007   struct AuthParam{
0008       std::string user;
0009       std::string password;
0010   };
0011 };
0012 
0013 typedef std::vector<Connection> result;
0014 
0015 void loadxml(const std::string &filename,
0016          const std::string &conn,
0017          std::string &user,
0018          std::string &pass)
0019 {
0020     using boost::property_tree::ptree;
0021     ptree pt;
0022 
0023     read_xml(filename, pt);
0024 
0025     for(auto const& v : pt.get_child("connectionlist")){
0026       if(v.first=="connection"){
0027     std::string con=v.second.get<std::string>("<xmlattr>.name",std::string(""));
0028     if(con==conn){
0029       for(auto const& p : v.second){
0030         if(p.first=="parameter"){
0031           std::string name=p.second.get<std::string>("<xmlattr>.name");
0032           std::string value=p.second.get<std::string>("<xmlattr>.value");
0033           if(name=="user"){
0034         user=value;
0035           }
0036           if(name=="password"){
0037         pass=value;
0038           }
0039         }
0040       }
0041     }
0042       }
0043     }
0044 }
0045 int main(){
0046   std::string conn("oracle://cms_orcon_adg/cms_lumi_prod");
0047   std::string user("");
0048   std::string pass("");
0049   loadxml("/afs/cern.ch/cms/lumi/DB/authentication.xml","oracle://cms_orcon_adg/cms_lumi_prod",user,pass);
0050   std::cout<<"user "<<user<<" , "<<pass<<std::endl;
0051 }