summaryrefslogtreecommitdiff
path: root/docs/samples/load_error_handling.cpp
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-06-30 12:47:19 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-06-30 12:47:19 +0000
commite73b54e60d5b8bc4234d6c4cf4fa978e175d68cb (patch)
treee95b3b15488dac3a28bb9b0a8e6bbc79d81587c5 /docs/samples/load_error_handling.cpp
parent8b1a9951559fc6420aad68c4f4e23f8b470cec0c (diff)
docs: Fixed sample comment, adding load error handling sample, added custom writer sample
git-svn-id: http://pugixml.googlecode.com/svn/trunk@552 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'docs/samples/load_error_handling.cpp')
-rw-r--r--docs/samples/load_error_handling.cpp29
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>");
+}