From a71564984253ade92fc4d3c9bf185807efc570bf Mon Sep 17 00:00:00 2001 From: Oskari Timperi Date: Wed, 1 Jun 2011 10:52:04 +0300 Subject: New classes: node and comment. Move functionality from element to node and derive element from node. This allows nodes to contain different types of nodes, e.g. comments mixed with normal elements. --- example.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'example.cpp') diff --git a/example.cpp b/example.cpp index fa1574c..bbc3bbd 100644 --- a/example.cpp +++ b/example.cpp @@ -22,27 +22,29 @@ * 3. This notice may not be removed or altered from any source * distribution. */ - + #include #include "sxml.h" using sxml::element; - +using sxml::comment; int main() { - element root("summary"); - - root.add_child(element("foo", "lorem ipsum")) - - .add_child(element("bar") - .add_child(element("foobar", "bazinga!")) - .set_attr("id", "1337")) - - .add_child(element("mother").add_child(element("child"))); - - std::cout << root.to_string(true) << std::endl; - + element *root = new element("root"); + + root->add_element("node")->set_attr("id", 0); + + root->add_child(new comment("yay, a comment!")); + root->add_element("node")->set_attr("id", 1); + + element *node = root->add_element("node")->set_attr("id", 3.1); + node = node->add_element("subnode") + node->add_element("subsubnode")->add_child( + new comment("i am in pretty deep waters here, man ..")); + + std::cout << root->to_string(true) << std::endl; + return 0; } -- cgit v1.2.3