2014-05-02 08:30:32 +02:00
|
|
|
#include "stdafx.h"
|
2014-07-11 13:59:13 +02:00
|
|
|
#include "Utilities/rXml.h"
|
2014-05-02 08:30:32 +02:00
|
|
|
|
2021-04-09 21:12:47 +02:00
|
|
|
rXmlNode::rXmlNode()
|
2014-05-02 08:30:32 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-05-28 13:36:45 +02:00
|
|
|
rXmlNode::rXmlNode(const pugi::xml_node& node)
|
2014-05-02 08:30:32 +02:00
|
|
|
{
|
2016-04-16 23:21:22 +02:00
|
|
|
handle = node;
|
2014-05-02 08:30:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<rXmlNode> rXmlNode::GetChildren()
|
|
|
|
{
|
2023-05-28 13:36:45 +02:00
|
|
|
if (handle)
|
2014-06-08 13:43:13 +02:00
|
|
|
{
|
2023-05-28 13:36:45 +02:00
|
|
|
if (const pugi::xml_node child = handle.first_child())
|
|
|
|
{
|
|
|
|
return std::make_shared<rXmlNode>(child);
|
|
|
|
}
|
2014-06-08 13:43:13 +02:00
|
|
|
}
|
2023-05-28 13:36:45 +02:00
|
|
|
|
|
|
|
return nullptr;
|
2014-05-02 08:30:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<rXmlNode> rXmlNode::GetNext()
|
|
|
|
{
|
2023-05-28 13:36:45 +02:00
|
|
|
if (handle)
|
2014-06-08 13:43:13 +02:00
|
|
|
{
|
2023-05-28 13:36:45 +02:00
|
|
|
if (const pugi::xml_node result = handle.next_sibling())
|
|
|
|
{
|
|
|
|
return std::make_shared<rXmlNode>(result);
|
|
|
|
}
|
2014-06-08 13:43:13 +02:00
|
|
|
}
|
2023-05-28 13:36:45 +02:00
|
|
|
|
|
|
|
return nullptr;
|
2014-05-02 08:30:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string rXmlNode::GetName()
|
|
|
|
{
|
2023-05-28 13:36:45 +02:00
|
|
|
if (handle)
|
|
|
|
{
|
|
|
|
if (const pugi::char_t* name = handle.name())
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
2014-05-02 08:30:32 +02:00
|
|
|
}
|
|
|
|
|
2023-05-28 13:36:45 +02:00
|
|
|
std::string rXmlNode::GetAttribute(const std::string& name)
|
2014-05-02 08:30:32 +02:00
|
|
|
{
|
2023-05-28 13:36:45 +02:00
|
|
|
if (handle)
|
|
|
|
{
|
|
|
|
const auto pred = [&name](const pugi::xml_attribute& attr) { return (name == attr.name()); };
|
|
|
|
if (const pugi::xml_attribute attr = handle.find_attribute(pred))
|
|
|
|
{
|
|
|
|
if (const pugi::char_t* value = attr.value())
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
2014-05-02 08:30:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string rXmlNode::GetNodeContent()
|
|
|
|
{
|
2023-05-28 13:36:45 +02:00
|
|
|
if (handle)
|
|
|
|
{
|
|
|
|
if (const pugi::xml_text text = handle.text())
|
|
|
|
{
|
|
|
|
if (const pugi::char_t* value = text.get())
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
2014-05-02 08:30:32 +02:00
|
|
|
}
|
|
|
|
|
2021-04-09 21:12:47 +02:00
|
|
|
rXmlDocument::rXmlDocument()
|
2014-05-02 08:30:32 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-17 23:18:33 +01:00
|
|
|
pugi::xml_parse_result rXmlDocument::Read(const std::string& data)
|
2014-05-02 08:30:32 +02:00
|
|
|
{
|
2023-05-28 13:36:45 +02:00
|
|
|
if (handle)
|
|
|
|
{
|
|
|
|
return handle.load_buffer(data.data(), data.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
2014-05-02 08:30:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<rXmlNode> rXmlDocument::GetRoot()
|
|
|
|
{
|
2023-05-28 13:36:45 +02:00
|
|
|
if (const pugi::xml_node root = handle.root())
|
|
|
|
{
|
|
|
|
return std::make_shared<rXmlNode>(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
2016-04-02 22:28:53 +02:00
|
|
|
}
|