/
Document.h
executable file
·63 lines (41 loc) · 1.47 KB
/
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
#ifndef __DOCUMENT_H__
#define __DOCUMENT_H__
#include <string>
#include <fstream>
#include "Node.h"
#include "Parser.h"
#include "Attribute.h"
#include "ElementNode.h"
#include "CDATANode.h"
#include <regex>
using namespace std;
namespace tinyXMLpp {
class Document
{
ElementNode* rootElement;
vector<Node*> childNodes;
bool isRootSet; //Keeps track of whether the root element was set or not. Root element should be set only once.
bool isEmptyText (const std::string& input) const;
void validate(Node* child);
void setRootElement (Node* child);
Node* getElementById (Node* node, const std::string& id);
void getElementsByTagName (Node* node, const std::string& tagName, vector<ElementNode*>& nodes);
public:
Document() : isRootSet(false), rootElement(nullptr) {}
~Document();
/*Returns the XML document element(node)*/
ElementNode* getRootElement() const;
/*call the function to commit the XML DOM to a file.*/
void write(const std::string& path) const;
void write(std::ostream& os) const;
/*Overloads for adding a node to the Document*/
void addChildNode (Node* child);
void addChildNode (Node* child,int index);
/*Overloads for removing a node to the Document*/
void removeChildNode (Node* child);
void removeChildNode (int index);
ElementNode* getElementById(const std::string& id);
vector<ElementNode*> getElementsByTagName(const std::string& tagName);
};
}
#endif