comparison dep/pugixml/docs/samples/traverse_walker.cpp @ 55:d10b6c6b432e

add xml lib, we will need to use it eventually
author Paper <mrpapersonic@gmail.com>
date Tue, 26 Sep 2023 12:37:08 -0400
parents
children
comparison
equal deleted inserted replaced
54:466ac9870df9 55:d10b6c6b432e
1 #include "pugixml.hpp"
2
3 #include <iostream>
4
5 const char* node_types[] =
6 {
7 "null", "document", "element", "pcdata", "cdata", "comment", "pi", "declaration"
8 };
9
10 // tag::impl[]
11 struct simple_walker: pugi::xml_tree_walker
12 {
13 virtual bool for_each(pugi::xml_node& node)
14 {
15 for (int i = 0; i < depth(); ++i) std::cout << " "; // indentation
16
17 std::cout << node_types[node.type()] << ": name='" << node.name() << "', value='" << node.value() << "'\n";
18
19 return true; // continue traversal
20 }
21 };
22 // end::impl[]
23
24 int main()
25 {
26 pugi::xml_document doc;
27 if (!doc.load_file("tree.xml")) return -1;
28
29 // tag::traverse[]
30 simple_walker walker;
31 doc.traverse(walker);
32 // end::traverse[]
33 }
34
35 // vim:et