summaryrefslogtreecommitdiff
path: root/src/core/XML.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/XML.cpp')
-rw-r--r--src/core/XML.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/core/XML.cpp b/src/core/XML.cpp
new file mode 100644
index 0000000..038cb86
--- /dev/null
+++ b/src/core/XML.cpp
@@ -0,0 +1,39 @@
+
+#include "XML.hpp"
+
+namespace ousia {
+namespace xml {
+
+void Node::serialize(std::ostream& out){
+ out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+ doSerialize(out, 0);
+}
+
+void Element::doSerialize(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->doSerialize(out, tabdepth + 1);
+ }
+ for (unsigned int t = 0; t < tabdepth; t++) {
+ out << '\t';
+ }
+ out << "</" << name << ">\n";
+}
+
+void Text::doSerialize(std::ostream& out, unsigned int tabdepth)
+{
+ for (unsigned int t = 0; t < tabdepth; t++) {
+ out << '\t';
+ }
+ out << text << '\n';
+}
+}
+}