aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example.cpp5
-rw-r--r--sxml.cpp14
2 files changed, 19 insertions, 0 deletions
diff --git a/example.cpp b/example.cpp
index 166ae98..8346749 100644
--- a/example.cpp
+++ b/example.cpp
@@ -43,6 +43,11 @@ int main()
node->add_element("subsubnode")->add_comment(
"i am in pretty deep waters here, man ..");
+ node = root->add_element("node")->set_attr("id", 6);
+ node = node->add_element("subnode")->set_attr("id", 66);
+
+ root->add_child(node);
+
std::cout << root->to_string(true) << std::endl;
return 0;
diff --git a/sxml.cpp b/sxml.cpp
index 0e23833..e09de0b 100644
--- a/sxml.cpp
+++ b/sxml.cpp
@@ -59,6 +59,20 @@ node::~node()
node *node::add_child(node *child)
{
+ if (child->m_parent != NULL)
+ {
+ node_list::iterator i = child->m_parent->m_children.begin();
+ for (; i != child->m_parent->m_children.end(); ++i)
+ {
+ if (*i == child)
+ {
+ child->m_parent->m_children.erase(i);
+ child->m_parent->set_modified(true);
+ break;
+ }
+ }
+ }
+
child->m_parent = this;
m_children.push_back(child);
set_modified(true);