source: icGREP/icgrep-devel/icgrep/combine/pugixml/docs/samples/xpath_query.cpp @ 5516

Last change on this file since 5516 was 5516, checked in by faldebey, 21 months ago

added combinatorial testing tool

File size: 1.2 KB
Line 
1#include "pugixml.hpp"
2
3#include <iostream>
4#include <string>
5
6int 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_query query_remote_tools("/Profile/Tools/Tool[@AllowRemote='true']");
14
15    pugi::xpath_node_set tools = query_remote_tools.evaluate_node_set(doc);
16    std::cout << "Remote tool: ";
17    tools[2].node().print(std::cout);
18
19    // Evaluate numbers via compiled query
20    pugi::xpath_query query_timeouts("sum(//Tool/@Timeout)");
21    std::cout << query_timeouts.evaluate_number(doc) << std::endl;
22
23    // Evaluate strings via compiled query for different context nodes
24    pugi::xpath_query query_name_valid("string-length(substring-before(@Filename, '_')) > 0 and @OutputFileMasks");
25    pugi::xpath_query query_name("concat(substring-before(@Filename, '_'), ' produces ', @OutputFileMasks)");
26
27    for (pugi::xml_node tool = doc.first_element_by_path("Profile/Tools/Tool"); tool; tool = tool.next_sibling())
28    {
29        std::string s = query_name.evaluate_string(tool);
30
31        if (query_name_valid.evaluate_boolean(tool)) std::cout << s << std::endl;
32    }
33// end::code[]
34}
35
36// vim:et
Note: See TracBrowser for help on using the repository browser.