Mercurial > minori
comparison dep/pugixml/docs/samples/traverse_walker.cpp @ 367:8d45d892be88 default tip
*: instead of pugixml, use Qt XML features
this means we have one extra Qt dependency though...
author | Paper <paper@tflc.us> |
---|---|
date | Sun, 17 Nov 2024 22:55:47 -0500 |
parents | 886f66775f31 |
children |
comparison
equal
deleted
inserted
replaced
366:886f66775f31 | 367:8d45d892be88 |
---|---|
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 |