diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-09-26 00:38:43 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-09-26 00:38:43 +0100 |
| commit | 3b6ddf4b140befd1286af26c34800a50b3ba3f56 (patch) | |
| tree | 93073a6bfc847c208c92988a3f3731fffc2bb587 | |
| parent | e486e70da8c3c65294e27c18ad9cb0e4a5fe8aaf (diff) | |
Use xpath for node_children.
| -rw-r--r-- | src/cxml.cc | 12 | ||||
| -rw-r--r-- | test/tests.cc | 4 |
2 files changed, 7 insertions, 9 deletions
diff --git a/src/cxml.cc b/src/cxml.cc index 2ca46ed..ddfa00f 100644 --- a/src/cxml.cc +++ b/src/cxml.cc @@ -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); diff --git a/test/tests.cc b/test/tests.cc index 4bf0ae7..ed8d2f4 100644 --- a/test/tests.cc +++ b/test/tests.cc @@ -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"); } |
