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