-
Notifications
You must be signed in to change notification settings - Fork 0
/
xml_document.h
70 lines (54 loc) · 1.9 KB
/
xml_document.h
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
#ifndef xml_document_h
#define xml_document_h
#include <string>
#include <vector>
/********************************************************************/
class XMLNode;
class XMLAttr {
public:
XMLAttr(const std::string& label, const std::string& value, XMLNode* parent=nullptr);
~XMLAttr();
const std::string& label() const;
const std::string& value() const;
private:
std::string label_;
std::string value_;
};
class XMLNode {
public:
XMLNode(const std::string& name, XMLNode* parent = nullptr);
XMLNode(const std::string& name, const std::string& value, XMLNode* parent);
~XMLNode();
void addNode(XMLNode* node);
int nodeCount() const;
const XMLNode* node(int index) const;
XMLNode* node(int index);
const std::vector<XMLNode*>& nodes() const { return nodes_; }
XMLNode* getNodeFromTag(const std::string& tag_name);
XMLNode* getNodeFromName(const std::string& node_name);
XMLNode* addValuedNode(const std::string& name, const std::string& value);
void addAttr(XMLAttr* attr);
XMLAttr* addValuedAttr(const std::string& label, const std::string& value);
int attrCount() const;
const XMLAttr* attr(int index) const;
XMLAttr* attr(int index);
const std::vector<XMLAttr*>& attributes() const { return attributes_; }
XMLAttr* getAttrFromName(const std::string& attr_name);
const std::string& name() const;
bool hasValue() const;
const std::string& value() const;
XMLNode* parent() const { return parent_; }
private:
std::string name_;
std::vector<XMLNode*> nodes_;
std::vector<XMLAttr*> attributes_;
std::string value_;
XMLNode* parent_;
};
class XMLDocument {
public:
static XMLNode* read_doc(const std::string& filename);
static bool write_doc(const XMLNode* node, const std::string& filename);
};
/********************************************************************/
#endif // xml_document_h