comparison dep/pugixml/docs/samples/xpath_error.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
5 int main()
6 {
7 pugi::xml_document doc;
8 if (!doc.load_file("xgconsole.xml")) return -1;
9
10 // tag::code[]
11 // Exception is thrown for incorrect query syntax
12 try
13 {
14 doc.select_nodes("//nodes[#true()]");
15 }
16 catch (const pugi::xpath_exception& e)
17 {
18 std::cout << "Select failed: " << e.what() << std::endl;
19 }
20
21 // Exception is thrown for incorrect query semantics
22 try
23 {
24 doc.select_nodes("(123)/next");
25 }
26 catch (const pugi::xpath_exception& e)
27 {
28 std::cout << "Select failed: " << e.what() << std::endl;
29 }
30
31 // Exception is thrown for query with incorrect return type
32 try
33 {
34 doc.select_nodes("123");
35 }
36 catch (const pugi::xpath_exception& e)
37 {
38 std::cout << "Select failed: " << e.what() << std::endl;
39 }
40 // end::code[]
41 }
42
43 // vim:et