Mercurial > minori
comparison dep/pugixml/docs/samples/xpath_variables.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 #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 |
