-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmlload.cpp
More file actions
40 lines (37 loc) · 1.39 KB
/
xmlload.cpp
File metadata and controls
40 lines (37 loc) · 1.39 KB
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
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
#include "rapidxml/rapidxml.hpp"
using namespace rapidxml;
using namespace std;
int main(void)
{
cout << "Parsing sad ElementStore..." << endl;
xml_document<> doc;
xml_node<> * root_node;
// Read the xml file into a vector
ifstream theFile ("ExemplaryXmlToTestLib.xml");
cout << "read" << endl;
vector<char> buffer((istreambuf_iterator<char>(theFile)), istreambuf_iterator<char>());
buffer.push_back('\0');
// Parse the buffer using the xml file parsing library into doc
doc.parse<0>(&buffer[0]);
// Find our root node
root_node = doc.first_node("ElementStore");
// Iterate over the Elements
for (xml_node<> * element_node = root_node->first_node("Element"); element_node; element_node = element_node->next_sibling())
{
cout << "Element:" << endl;
cout << "Type:" << element_node->first_attribute("type")->value() << endl;
cout << "Model:" << element_node->first_attribute("model")->value() << endl;
// Interate over the subElements
for(xml_node<> * subElement_node = element_node->first_node("SubElement"); subElement_node; subElement_node = subElement_node->next_sibling())
{
cout << "Category: " << subElement_node->first_attribute("category")->value() << endl;
cout << "Node Value: " << subElement_node->value() << endl;
}
cout << endl;
}
}