summaryrefslogtreecommitdiff
path: root/src/core/XML.cpp
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-09 01:14:09 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-09 01:14:09 +0100
commite44fb038ec4404f2c38b698ec95c80d051b8d0cf (patch)
tree95ae8fe8728ddd9fb8456973a095f4b44ceaee70 /src/core/XML.cpp
parent0605eed698443dc18c48340084507c90e97a9333 (diff)
parent4ec16559eba87553241e2e20a9e31a62b7aed08a (diff)
Merge branch 'master' of somweyr.de:ousia
Conflicts: application/src/core/model/Document.cpp application/src/core/model/Domain.cpp
Diffstat (limited to 'src/core/XML.cpp')
-rw-r--r--src/core/XML.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/core/XML.cpp b/src/core/XML.cpp
index 038cb86..7f03b35 100644
--- a/src/core/XML.cpp
+++ b/src/core/XML.cpp
@@ -4,12 +4,16 @@
namespace ousia {
namespace xml {
-void Node::serialize(std::ostream& out){
+void Node::serialize(std::ostream &out, const std::string &doctype)
+{
out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+ if (doctype != "") {
+ out << doctype << "\n";
+ }
doSerialize(out, 0);
}
-void Element::doSerialize(std::ostream& out, unsigned int tabdepth)
+void Element::doSerialize(std::ostream &out, unsigned int tabdepth)
{
for (unsigned int t = 0; t < tabdepth; t++) {
out << '\t';
@@ -18,17 +22,22 @@ void Element::doSerialize(std::ostream& out, unsigned int tabdepth)
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';
+ // if we have no children, we close the tag immediately.
+ if (children.size() == 0) {
+ out << "/>\n";
+ } else {
+ out << ">\n";
+ for (auto &n : children) {
+ n->doSerialize(out, tabdepth + 1);
+ }
+ for (unsigned int t = 0; t < tabdepth; t++) {
+ out << '\t';
+ }
+ out << "</" << name << ">\n";
}
- out << "</" << name << ">\n";
}
-void Text::doSerialize(std::ostream& out, unsigned int tabdepth)
+void Text::doSerialize(std::ostream &out, unsigned int tabdepth)
{
for (unsigned int t = 0; t < tabdepth; t++) {
out << '\t';