summaryrefslogtreecommitdiff
path: root/docs/samples/load_error_handling.cpp
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-04-08 21:44:16 -0700
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-04-08 21:44:16 -0700
commit65e90b2d7a86383243e380b2658fad26dce370f0 (patch)
tree95f418c94216831b595a98f2e56768a6bdcbdab9 /docs/samples/load_error_handling.cpp
parent084ecd454a06d6da0304d0b7ccde8e8917b1ea26 (diff)
docs: Add docs folder from master
Diffstat (limited to 'docs/samples/load_error_handling.cpp')
-rw-r--r--docs/samples/load_error_handling.cpp33
1 files changed, 33 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..d1e5a49
--- /dev/null
+++ b/docs/samples/load_error_handling.cpp
@@ -0,0 +1,33 @@
+#include "pugixml.hpp"
+
+#include <iostream>
+
+void check_xml(const char* source)
+{
+// tag::code[]
+ pugi::xml_document doc;
+ pugi::xml_parse_result result = doc.load_string(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";
+ }
+// end::code[]
+}
+
+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>");
+}
+
+// vim:et