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
|
|
|
|
2016-04-16 23:21:22 +02:00
|
|
|
rXmlNode::rXmlNode() : handle()
|
2014-05-02 08:30:32 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-04-16 23:21:22 +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()
|
|
|
|
{
|
2016-04-02 22:28:53 +02:00
|
|
|
// it.begin() returns node_iterator*, *it.begin() return node*.
|
2016-04-16 23:21:22 +02:00
|
|
|
pugi::xml_object_range<pugi::xml_node_iterator> it = handle.children();
|
2016-04-02 22:28:53 +02:00
|
|
|
pugi::xml_node begin = *it.begin();
|
|
|
|
|
|
|
|
if (begin)
|
2014-06-08 13:43:13 +02:00
|
|
|
{
|
2016-04-16 23:21:22 +02:00
|
|
|
return std::make_shared<rXmlNode>(begin);
|
2014-06-08 13:43:13 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-02 22:28:53 +02:00
|
|
|
return nullptr;
|
2014-06-08 13:43:13 +02:00
|
|
|
}
|
2014-05-02 08:30:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<rXmlNode> rXmlNode::GetNext()
|
|
|
|
{
|
2016-04-16 23:21:22 +02:00
|
|
|
pugi::xml_node result = handle.next_sibling();
|
2014-06-08 13:43:13 +02:00
|
|
|
if (result)
|
|
|
|
{
|
2016-04-16 23:21:22 +02:00
|
|
|
return std::make_shared<rXmlNode>(result);
|
2014-06-08 13:43:13 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-02 22:28:53 +02:00
|
|
|
return nullptr;
|
2014-06-08 13:43:13 +02:00
|
|
|
}
|
2014-05-02 08:30:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string rXmlNode::GetName()
|
|
|
|
{
|
2016-04-16 23:21:22 +02:00
|
|
|
return handle.name();
|
2014-05-02 08:30:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string rXmlNode::GetAttribute(const std::string &name)
|
|
|
|
{
|
2016-04-02 22:28:53 +02:00
|
|
|
auto pred = [&name](pugi::xml_attribute attr) { return (name == attr.name()); };
|
2016-04-16 23:21:22 +02:00
|
|
|
return handle.find_attribute(pred).value();
|
2014-05-02 08:30:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string rXmlNode::GetNodeContent()
|
|
|
|
{
|
2016-04-16 23:21:22 +02:00
|
|
|
return handle.text().get();
|
2014-05-02 08:30:32 +02:00
|
|
|
}
|
|
|
|
|
2016-04-16 23:21:22 +02:00
|
|
|
rXmlDocument::rXmlDocument() : handle()
|
2014-05-02 08:30:32 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void rXmlDocument::Load(const std::string & path)
|
|
|
|
{
|
2016-04-02 22:28:53 +02:00
|
|
|
// TODO: Unsure of use of c_str.
|
2016-04-16 23:21:22 +02:00
|
|
|
handle.load_file(path.c_str());
|
2014-05-02 08:30:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<rXmlNode> rXmlDocument::GetRoot()
|
|
|
|
{
|
2016-04-16 23:21:22 +02:00
|
|
|
return std::make_shared<rXmlNode>(handle.root());
|
2016-04-02 22:28:53 +02:00
|
|
|
}
|
|
|
|
|