comparison dep/pugixml/docs/samples/xpath_variables.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 #include <string>
5
6 int main()
7 {
8 pugi::xml_document doc;
9 if (!doc.load_file("xgconsole.xml")) return -1;
10
11 // tag::code[]
12 // Select nodes via compiled query
13 pugi::xpath_variable_set vars;
14 vars.add("remote", pugi::xpath_type_boolean);
15
16 pugi::xpath_query query_remote_tools("/Profile/Tools/Tool[@AllowRemote = string($remote)]", &vars);
17
18 vars.set("remote", true);
19 pugi::xpath_node_set tools_remote = query_remote_tools.evaluate_node_set(doc);
20
21 vars.set("remote", false);
22 pugi::xpath_node_set tools_local = query_remote_tools.evaluate_node_set(doc);
23
24 std::cout << "Remote tool: ";
25 tools_remote[2].node().print(std::cout);
26
27 std::cout << "Local tool: ";
28 tools_local[0].node().print(std::cout);
29
30 // You can pass the context directly to select_nodes/select_node
31 pugi::xpath_node_set tools_local_imm = doc.select_nodes("/Profile/Tools/Tool[@AllowRemote = string($remote)]", &vars);
32
33 std::cout << "Local tool imm: ";
34 tools_local_imm[0].node().print(std::cout);
35 // end::code[]
36 }
37
38 // vim:et