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