From: <vac...@us...> - 2010-03-17 12:26:48
|
Revision: 178 http://xmlwrapp.svn.sourceforge.net/xmlwrapp/?rev=178&view=rev Author: vaclavslavik Date: 2010-03-17 12:26:33 +0000 (Wed, 17 Mar 2010) Log Message: ----------- Add xml::node::clear(). Modified Paths: -------------- trunk/NEWS trunk/include/xmlwrapp/node.h trunk/src/libxml/node.cxx trunk/tests/node/test_node.cxx Added Paths: ----------- trunk/tests/node/data/04c.out Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2010-03-11 15:30:57 UTC (rev 177) +++ trunk/NEWS 2010-03-17 12:26:33 UTC (rev 178) @@ -8,6 +8,8 @@ Fixed compilation with Sun Studio compiler. + Added xml::node::clear() method. + Version 0.6.2 Fixed xml::tree_parser to fail on non-fatal parser errors. Modified: trunk/include/xmlwrapp/node.h =================================================================== --- trunk/include/xmlwrapp/node.h 2010-03-11 15:30:57 UTC (rev 177) +++ trunk/include/xmlwrapp/node.h 2010-03-17 12:26:33 UTC (rev 178) @@ -778,6 +778,13 @@ size_type erase(const char *name); /** + Erases all children nodes. + + @since 0.7.0 + */ + void clear(); + + /** Sort all the children nodes of this node using one of thier attributes. Only nodes that are of xml::node::type_element will be sorted, and they must have the given node_name. Modified: trunk/src/libxml/node.cxx =================================================================== --- trunk/src/libxml/node.cxx 2010-03-11 15:30:57 UTC (rev 177) +++ trunk/src/libxml/node.cxx 2010-03-17 12:26:33 UTC (rev 178) @@ -700,6 +700,19 @@ } +void node::clear() +{ + xmlNodePtr n = pimpl_->xmlnode_; + + if ( !n->children ) + return; + + xmlFreeNodeList(n->children); + n->children = + n->last = NULL; +} + + void node::sort(const char *node_name, const char *attr_name) { xmlNodePtr i(pimpl_->xmlnode_->children), next(0); Added: trunk/tests/node/data/04c.out =================================================================== --- trunk/tests/node/data/04c.out (rev 0) +++ trunk/tests/node/data/04c.out 2010-03-17 12:26:33 UTC (rev 178) @@ -0,0 +1,2 @@ +<?xml version="1.0"?> +<root/> Modified: trunk/tests/node/test_node.cxx =================================================================== --- trunk/tests/node/test_node.cxx 2010-03-11 15:30:57 UTC (rev 177) +++ trunk/tests/node/test_node.cxx 2010-03-17 12:26:33 UTC (rev 178) @@ -329,6 +329,21 @@ } +BOOST_AUTO_TEST_CASE( clear ) +{ + xml::tree_parser parser(test_file_path("node/data/04.xml").c_str()); + + xml::node &root = parser.get_document().get_root_node(); + + BOOST_REQUIRE( root.size() > 0 ); + + root.clear(); + + BOOST_CHECK( root.empty() ); + BOOST_CHECK( is_same_as_file(root, "node/data/04c.out") ); +} + + /* * These tests check xml::node::insert() */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |