Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-04 22:55:00

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, const std::string &conn, std::string &user, std::string &pass) {
0016   using boost::property_tree::ptree;
0017   ptree pt;
0018 
0019   read_xml(filename, pt);
0020 
0021   for (auto const &v : pt.get_child("connectionlist")) {
0022     if (v.first == "connection") {
0023       std::string con = v.second.get<std::string>("<xmlattr>.name", std::string(""));
0024       if (con == conn) {
0025         for (auto const &p : v.second) {
0026           if (p.first == "parameter") {
0027             std::string name = p.second.get<std::string>("<xmlattr>.name");
0028             std::string value = p.second.get<std::string>("<xmlattr>.value");
0029             if (name == "user") {
0030               user = value;
0031             }
0032             if (name == "password") {
0033               pass = value;
0034             }
0035           }
0036         }
0037       }
0038     }
0039   }
0040 }
0041 int main() {
0042   std::string conn("oracle://cms_orcon_adg/cms_lumi_prod");
0043   std::string user("");
0044   std::string pass("");
0045   loadxml("/afs/cern.ch/cms/lumi/DB/authentication.xml", "oracle://cms_orcon_adg/cms_lumi_prod", user, pass);
0046   std::cout << "user " << user << " , " << pass << std::endl;
0047 }