comparison dep/pugixml/docs/samples/traverse_base.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 <string.h>
4 #include <iostream>
5
6 int main()
7 {
8 pugi::xml_document doc;
9 if (!doc.load_file("xgconsole.xml")) return -1;
10
11 pugi::xml_node tools = doc.child("Profile").child("Tools");
12
13 // tag::basic[]
14 for (pugi::xml_node tool = tools.first_child(); tool; tool = tool.next_sibling())
15 {
16 std::cout << "Tool:";
17
18 for (pugi::xml_attribute attr = tool.first_attribute(); attr; attr = attr.next_attribute())
19 {
20 std::cout << " " << attr.name() << "=" << attr.value();
21 }
22
23 std::cout << std::endl;
24 }
25 // end::basic[]
26
27 std::cout << std::endl;
28
29 // tag::data[]
30 for (pugi::xml_node tool = tools.child("Tool"); tool; tool = tool.next_sibling("Tool"))
31 {
32 std::cout << "Tool " << tool.attribute("Filename").value();
33 std::cout << ": AllowRemote " << tool.attribute("AllowRemote").as_bool();
34 std::cout << ", Timeout " << tool.attribute("Timeout").as_int();
35 std::cout << ", Description '" << tool.child_value("Description") << "'\n";
36 }
37 // end::data[]
38
39 std::cout << std::endl;
40
41 // tag::contents[]
42 std::cout << "Tool for *.dae generation: " << tools.find_child_by_attribute("Tool", "OutputFileMasks", "*.dae").attribute("Filename").value() << "\n";
43
44 for (pugi::xml_node tool = tools.child("Tool"); tool; tool = tool.next_sibling("Tool"))
45 {
46 std::cout << "Tool " << tool.attribute("Filename").value() << "\n";
47 }
48 // end::contents[]
49 }
50
51 // vim:et