Use xpath for node_children.
authorCarl Hetherington <cth@carlh.net>
Wed, 25 Sep 2013 23:38:43 +0000 (00:38 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 25 Sep 2013 23:38:43 +0000 (00:38 +0100)
src/cxml.cc
test/tests.cc

index 2ca46ed46971f97d2964f0065d22856cb2219b25..ddfa00f3d90ff03411f17bd0e9575a76cb031623 100644 (file)
@@ -57,17 +57,11 @@ cxml::Node::optional_node_child (string name) const
 list<shared_ptr<cxml::Node> >
 cxml::Node::node_children (string name) const
 {
-       /* XXX: using find / get_path should work here, but I can't follow
-          how get_path works.
-       */
-
-       xmlpp::Node::NodeList c = _node->get_children ();
+       xmlpp::NodeSet c = _node->find (name);
        
        list<shared_ptr<cxml::Node> > n;
-       for (xmlpp::Node::NodeList::iterator i = c.begin (); i != c.end(); ++i) {
-               if ((*i)->get_name() == name) {
-                       n.push_back (shared_ptr<Node> (new Node (*i)));
-               }
+       for (xmlpp::NodeSet::iterator i = c.begin (); i != c.end(); ++i) {
+               n.push_back (shared_ptr<Node> (new Node (*i)));
        }
        
        _taken.push_back (name);
index 4bf0ae7ed32a9ce78bbc3b563d2ca8c5b109e6ad..ed8d2f4a3129b2bdcba04b9950e4af242ccd0457 100644 (file)
@@ -62,4 +62,8 @@ BOOST_AUTO_TEST_CASE (test)
        BOOST_CHECK_EQUAL (document.optional_bool_child("E").get(), true);
        BOOST_CHECK_THROW (document.optional_bool_child("F"), cxml::Error);
        BOOST_CHECK (!document.optional_bool_child("G"));
+
+       BOOST_CHECK_EQUAL (document.node_children("F").size(), 2);
+       BOOST_CHECK_EQUAL (document.node_children("F").front()->content(), "1");
+       BOOST_CHECK_EQUAL (document.node_children("F").back()->content(), "2");
 }