/
rXml.cpp
72 lines (60 loc) · 1.24 KB
/
rXml.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "stdafx.h"
#include "Utilities/rXml.h"
rXmlNode::rXmlNode() : handle()
{
}
rXmlNode::rXmlNode(const pugi::xml_node &node)
{
handle = node;
}
std::shared_ptr<rXmlNode> rXmlNode::GetChildren()
{
// it.begin() returns node_iterator*, *it.begin() return node*.
pugi::xml_object_range<pugi::xml_node_iterator> it = handle.children();
pugi::xml_node begin = *it.begin();
if (begin)
{
return std::make_shared<rXmlNode>(begin);
}
else
{
return nullptr;
}
}
std::shared_ptr<rXmlNode> rXmlNode::GetNext()
{
pugi::xml_node result = handle.next_sibling();
if (result)
{
return std::make_shared<rXmlNode>(result);
}
else
{
return nullptr;
}
}
std::string rXmlNode::GetName()
{
return handle.name();
}
std::string rXmlNode::GetAttribute(const std::string &name)
{
auto pred = [&name](pugi::xml_attribute attr) { return (name == attr.name()); };
return handle.find_attribute(pred).value();
}
std::string rXmlNode::GetNodeContent()
{
return handle.text().get();
}
rXmlDocument::rXmlDocument() : handle()
{
}
void rXmlDocument::Load(const std::string & path)
{
// TODO: Unsure of use of c_str.
handle.load_file(path.c_str());
}
std::shared_ptr<rXmlNode> rXmlDocument::GetRoot()
{
return std::make_shared<rXmlNode>(handle.root());
}