atm-admin/src/XMLStorage.cpp

35 lines
967 B
C++
Raw Normal View History

2025-06-13 09:15:55 +00:00
#include <iomanip>
#include <iostream>
#include "../libs/XMLStorage.h"
#include "pugixml.hpp"
namespace AtmAdmin {
void XMLStorage::initXMLDoc () {
pugi::xml_parse_result res = m_doc.load_file("./data/users.xml");
if (!res) {
std::cerr << "Error occurred: " << res.description();
exit(EXIT_FAILURE);
}
}
// getXMLData retrieves the data required by XMLStorage.
pugi::xml_node XMLStorage::getXMLUserData (const std::string& toSearch) {
pugi::xml_node data = m_doc.first_child().child("accounts").find_child_by_attribute("account", "owner", toSearch.c_str());
if (data.empty()) {
std::cerr << "Account not found, exiting.";
std::cout << data.name();
exit(EXIT_FAILURE);
}
return data;
}
// void XMLStorage::updateXMLData (const std::string& toSearch) {
// // TODO: FILL WITH CODE THAT UPDATES DATABASE
// }
}