comparison dep/pugixml/docs/samples/load_error_handling.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 void check_xml(const char* source)
6 {
7 // tag::code[]
8 pugi::xml_document doc;
9 pugi::xml_parse_result result = doc.load_string(source);
10
11 if (result)
12 {
13 std::cout << "XML [" << source << "] parsed without errors, attr value: [" << doc.child("node").attribute("attr").value() << "]\n\n";
14 }
15 else
16 {
17 std::cout << "XML [" << source << "] parsed with errors, attr value: [" << doc.child("node").attribute("attr").value() << "]\n";
18 std::cout << "Error description: " << result.description() << "\n";
19 std::cout << "Error offset: " << result.offset << " (error at [..." << (source + result.offset) << "]\n\n";
20 }
21 // end::code[]
22 }
23
24 int main()
25 {
26 check_xml("<node attr='value'><child>text</child></node>");
27 check_xml("<node attr='value'><child>text</chil></node>");
28 check_xml("<node attr='value'><child>text</child>");
29 check_xml("<node attr='value\"><child>text</child></node>");
30 check_xml("<node attr='value'><#tag /></node>");
31 }
32
33 // vim:et