Files
ARMSX3/Utilities/rXml.cpp
T

71 lines
1.2 KiB
C++
Raw Normal View History

#include "stdafx.h"
2014-07-11 21:59:13 +10:00
#include "Utilities/rXml.h"
2016-04-17 00:21:22 +03:00
rXmlNode::rXmlNode() : handle()
{
}
2016-04-17 00:21:22 +03:00
rXmlNode::rXmlNode(const pugi::xml_node &node)
{
2016-04-17 00:21:22 +03:00
handle = node;
2016-04-02 16:28:53 -04:00
}
std::shared_ptr<rXmlNode> rXmlNode::GetChildren()
{
2016-04-02 16:28:53 -04:00
// it.begin() returns node_iterator*, *it.begin() return node*.
2016-04-17 00:21:22 +03:00
pugi::xml_object_range<pugi::xml_node_iterator> it = handle.children();
2016-04-02 16:28:53 -04:00
pugi::xml_node begin = *it.begin();
if (begin)
2014-06-08 13:43:13 +02:00
{
2016-04-17 00:21:22 +03:00
return std::make_shared<rXmlNode>(begin);
2014-06-08 13:43:13 +02:00
}
else
{
2016-04-02 16:28:53 -04:00
return nullptr;
2014-06-08 13:43:13 +02:00
}
}
std::shared_ptr<rXmlNode> rXmlNode::GetNext()
{
2016-04-17 00:21:22 +03:00
pugi::xml_node result = handle.next_sibling();
2014-06-08 13:43:13 +02:00
if (result)
{
2016-04-17 00:21:22 +03:00
return std::make_shared<rXmlNode>(result);
2014-06-08 13:43:13 +02:00
}
else
{
2016-04-02 16:28:53 -04:00
return nullptr;
2014-06-08 13:43:13 +02:00
}
}
std::string rXmlNode::GetName()
{
2016-04-17 00:21:22 +03:00
return handle.name();
}
std::string rXmlNode::GetAttribute(const std::string &name)
{
2016-04-02 16:28:53 -04:00
auto pred = [&name](pugi::xml_attribute attr) { return (name == attr.name()); };
2016-04-17 00:21:22 +03:00
return handle.find_attribute(pred).value();
}
std::string rXmlNode::GetNodeContent()
{
2020-12-22 10:02:23 +03:00
return handle.text().get();
2016-04-02 16:28:53 -04:00
}
2016-04-17 00:21:22 +03:00
rXmlDocument::rXmlDocument() : handle()
2016-04-02 16:28:53 -04:00
{
}
2017-09-03 22:29:20 +03:00
void rXmlDocument::Read(const std::string& data)
{
2017-09-03 22:29:20 +03:00
handle.load_buffer(data.data(), data.size());
}
std::shared_ptr<rXmlNode> rXmlDocument::GetRoot()
{
2016-04-17 00:21:22 +03:00
return std::make_shared<rXmlNode>(handle.root());
2016-04-02 16:28:53 -04:00
}