Skip to content
Snippets Groups Projects
loading_file.rst 860 B
Newer Older
.. _loadfile:

**************************************
Loading an xml file into a Karabo Hash
**************************************

The next code example shows how to use `loadFromFile` to load the content of an XML file into a Karabo
Hash:

.. code-block:: c++

    try {

        // We assume the file is inside the Karabo installation
        std::string file_name_path(karabo::util::Version::getPathToKaraboInstallation() + "/var/data/my_file.xml");
        
        // Load the content of the file into 'config'.
        // This is protected in a try-catch block, in case something is wrong (the file format can be
        // corrupt, for instance)
        Hash config;
        loadFromFile(config, file_name_path);

    } catch (std::exception& e) {
        KARABO_LOG_FRAMEWORK_WARN << "Failed to load File: " << file_path << " : " << e.what();
    }