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

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

added combinatorial testing tool

File size: 1.0 KB
Line 
1#include "pugixml.hpp"
2
3#include <iostream>
4
5void 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
24int 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
Note: See TracBrowser for help on using the repository browser.