diff options
Diffstat (limited to 'docs/samples/load_error_handling.cpp')
-rw-r--r-- | docs/samples/load_error_handling.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/docs/samples/load_error_handling.cpp b/docs/samples/load_error_handling.cpp new file mode 100644 index 0000000..9b274ba --- /dev/null +++ b/docs/samples/load_error_handling.cpp @@ -0,0 +1,29 @@ +#include "pugixml.hpp"
+
+#include <iostream>
+
+void check_xml(const char* source)
+{
+//[code_load_error_handling
+ pugi::xml_document doc;
+ pugi::xml_parse_result result = doc.load(source);
+
+ if (result)
+ std::cout << "XML [" << source << "] parsed without errors, attr value: [" << doc.child("node").attribute("attr").value() << "]\n\n";
+ else
+ {
+ std::cout << "XML [" << source << "] parsed with errors, attr value: [" << doc.child("node").attribute("attr").value() << "]\n";
+ std::cout << "Error description: " << result.description() << "\n";
+ std::cout << "Error offset: " << result.offset << " (error at [..." << (source + result.offset) << "]\n\n";
+ }
+//]
+}
+
+int main()
+{
+ check_xml("<node attr='value'><child>text</child></node>");
+ check_xml("<node attr='value'><child>text</chil></node>");
+ check_xml("<node attr='value'><child>text</child>");
+ check_xml("<node attr='value\"><child>text</child></node>");
+ check_xml("<node attr='value'><#tag /></node>");
+}
|