1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-24 11:43:05 +01:00
rpcs3/Utilities/rXml.cpp

108 lines
1.6 KiB
C++
Raw Normal View History

#include "stdafx.h"
2014-07-11 13:59:13 +02:00
#include "Utilities/rXml.h"
2021-04-09 21:12:47 +02:00
rXmlNode::rXmlNode()
{
}
rXmlNode::rXmlNode(const pugi::xml_node& node)
{
handle = node;
}
std::shared_ptr<rXmlNode> rXmlNode::GetChildren()
{
if (handle)
{
if (const pugi::xml_node child = handle.first_child())
{
return std::make_shared<rXmlNode>(child);
}
}
return nullptr;
}
std::shared_ptr<rXmlNode> rXmlNode::GetNext()
{
if (handle)
{
if (const pugi::xml_node result = handle.next_sibling())
{
return std::make_shared<rXmlNode>(result);
}
}
return nullptr;
}
std::string rXmlNode::GetName()
{
if (handle)
{
if (const pugi::char_t* name = handle.name())
{
return name;
}
}
return {};
}
std::string rXmlNode::GetAttribute(const std::string& name)
{
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 {};
}
std::string rXmlNode::GetNodeContent()
{
if (handle)
{
if (const pugi::xml_text text = handle.text())
{
if (const pugi::char_t* value = text.get())
{
return value;
}
}
}
return {};
}
2021-04-09 21:12:47 +02:00
rXmlDocument::rXmlDocument()
{
}
pugi::xml_parse_result rXmlDocument::Read(const std::string& data)
{
if (handle)
{
return handle.load_buffer(data.data(), data.size());
}
return {};
}
std::shared_ptr<rXmlNode> rXmlDocument::GetRoot()
{
if (const pugi::xml_node root = handle.root())
{
return std::make_shared<rXmlNode>(root);
}
return nullptr;
}