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