Add sax converter from json to xml
[anna.git] / source / json / functions.cpp
diff --git a/source/json/functions.cpp b/source/json/functions.cpp
new file mode 100644 (file)
index 0000000..1806919
--- /dev/null
@@ -0,0 +1,23 @@
+// ANNA - Anna is Not Nothingness Anymore                                                         //
+//                                                                                                //
+// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
+//                                                                                                //
+// See project site at http://redmine.teslayout.com/projects/anna-suite                           //
+// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
+
+
+#include <anna/json/functions.hpp>
+#include <anna/json/SaxConsumer.hpp>
+
+
+std::string anna::json::functions::json2xml(const std::string &json, bool & success) {
+
+  // create a SAX event consumer object
+  anna::json::SaxConsumer consumer;
+
+  // parse and serialize JSON
+  success = nlohmann::json::sax_parse(json, &consumer);
+
+  // output the result of sax_parse
+  return consumer.getResult().str();
+}