Belle II Software  release-08-01-10
XmlFile.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #pragma once
9 
10 #include <TObject.h>
11 #include <string>
12 #include <fstream>
13 #include <boost/property_tree/xml_parser.hpp>
14 
15 namespace Belle2 {
21  class XmlFile : public TObject {
22 
23  public:
25  XmlFile() {};
26 
28  virtual ~XmlFile()
29  {
30  }
31 
33  void readXml(std::string xmlFileName)
34  {
35  std::ifstream t(xmlFileName);
36  std::stringstream buffer;
37  buffer << t.rdbuf();
38  m_data = buffer.str();
39  }
40 
42  std::string getData()
43  {
44  return m_data;
45  }
46 
48  void fillPropertyTree(boost::property_tree::ptree& tree)
49  {
50  std::stringstream ss; ss << m_data;
51  using boost::property_tree::ptree;
52  read_xml(ss, tree);
53  }
54 
55  private:
57  std::string m_data{""};
58 
59  ClassDef(XmlFile, 1)
60  };
62 }
DB object which stores whole xml.
Definition: XmlFile.h:21
std::string getData()
Get content as string.
Definition: XmlFile.h:42
void readXml(std::string xmlFileName)
Read content from xml file.
Definition: XmlFile.h:33
void fillPropertyTree(boost::property_tree::ptree &tree)
Populate boost PropertyTree with stored data.
Definition: XmlFile.h:48
XmlFile()
Constructor.
Definition: XmlFile.h:25
std::string m_data
The xml data as string.
Definition: XmlFile.h:57
virtual ~XmlFile()
Destructor.
Definition: XmlFile.h:28
Abstract base class for different kinds of events.