diff options
author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-01-08 15:17:40 +0100 |
---|---|---|
committer | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-01-08 15:17:40 +0100 |
commit | 33b92b72ed160f22dc627e841d5f84de4ebc0c6c (patch) | |
tree | 597ebe6611f4317901817d05e00d8388e9960bf0 /src/core | |
parent | fd8ce97afb16e17102ec8f109103ed334ad0e939 (diff) |
Changed the DemoOutput algorithm as suggested by Andreas: We first transform the document graph to an XML tree and the XML tree in turn has the methods to serialize to XML text, or, in this case, XHTML text.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/XML.cpp | 11 | ||||
-rw-r--r-- | src/core/XML.hpp | 17 |
2 files changed, 20 insertions, 8 deletions
diff --git a/src/core/XML.cpp b/src/core/XML.cpp index ad69ba1..038cb86 100644 --- a/src/core/XML.cpp +++ b/src/core/XML.cpp @@ -4,7 +4,12 @@ namespace ousia { namespace xml { -void Element::serialize(std::ostream& out, unsigned int tabdepth) +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'; @@ -15,7 +20,7 @@ void Element::serialize(std::ostream& out, unsigned int tabdepth) } out << ">\n"; for (auto &n : children) { - n->serialize(out, tabdepth + 1); + n->doSerialize(out, tabdepth + 1); } for (unsigned int t = 0; t < tabdepth; t++) { out << '\t'; @@ -23,7 +28,7 @@ void Element::serialize(std::ostream& out, unsigned int tabdepth) out << "</" << name << ">\n"; } -void Text::serialize(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'; diff --git a/src/core/XML.hpp b/src/core/XML.hpp index 824d6ce..9ca124a 100644 --- a/src/core/XML.hpp +++ b/src/core/XML.hpp @@ -57,18 +57,25 @@ namespace xml { * implement. */ class Node : public Managed { + public: Node(Manager &mgr) : Managed(mgr){}; /** - * When called this Node should serialize its data and write it to the - * given output stream. In case of Elements this includes child elements. + * This method writes an XML prolog and the XML representing the current + * node, including all children, to the given output stream. + * @param out is the output stream the serialized data shall be written to. + */ + void serialize(std::ostream &out); + /** + * This method just writes the XML representation of this node to the + * output stream, without the XML prolog. * * @param out the output stream the serialized data shall be written * to. * @param tabdepth the current tabdepth for prettier output. */ - virtual void serialize(std::ostream &out, unsigned int tabdepth) = 0; + virtual void doSerialize(std::ostream &out, unsigned int tabdepth) = 0; }; /** @@ -103,7 +110,7 @@ public: * * The end tag of this element. * */ - void serialize(std::ostream &out, unsigned int tabdepth = 0) override; + void doSerialize(std::ostream &out, unsigned int tabdepth) override; }; class Text : public Node { @@ -116,7 +123,7 @@ public: * This just writes the text to the output. * */ - void serialize(std::ostream &out, unsigned int tabdepth = 0) override; + void doSerialize(std::ostream &out, unsigned int tabdepth) override; }; } } |