From fd8ce97afb16e17102ec8f109103ed334ad0e939 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Tue, 6 Jan 2015 22:38:49 +0100 Subject: added XML classes including Serialization functions and added a test for it. I tried not to include Managed.hpp to prevent further overhead but I failed miserably. --- src/core/XML.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/core/XML.cpp (limited to 'src/core/XML.cpp') diff --git a/src/core/XML.cpp b/src/core/XML.cpp new file mode 100644 index 0000000..ad69ba1 --- /dev/null +++ b/src/core/XML.cpp @@ -0,0 +1,34 @@ + +#include "XML.hpp" + +namespace ousia { +namespace xml { + +void Element::serialize(std::ostream& out, unsigned int tabdepth) +{ + for (unsigned int t = 0; t < tabdepth; t++) { + out << '\t'; + } + out << '<' << name; + for (auto &a : attributes) { + out << ' ' << a.first << "=\"" << a.second << '\"'; + } + out << ">\n"; + for (auto &n : children) { + n->serialize(out, tabdepth + 1); + } + for (unsigned int t = 0; t < tabdepth; t++) { + out << '\t'; + } + out << "\n"; +} + +void Text::serialize(std::ostream& out, unsigned int tabdepth) +{ + for (unsigned int t = 0; t < tabdepth; t++) { + out << '\t'; + } + out << text << '\n'; +} +} +} -- cgit v1.2.3