read_file (file);
}
+cxml::Document::Document ()
+{
+ _parser = new xmlpp::DomParser ();
+}
+
cxml::Document::~Document ()
{
delete _parser;
}
_node = _parser->get_document()->get_root_node ();
- if (_node->get_name() != _root_name) {
+ if (!_root_name.empty() && _node->get_name() != _root_name) {
throw cxml::Error ("unrecognised root node");
+ } else if (_root_name.empty ()) {
+ _root_name = _node->get_name ();
}
}
class Document : public Node
{
public:
+ Document ();
Document (std::string root_name);
Document (std::string root_name, boost::filesystem::path);
+ virtual ~Document ();
+
void read_file (boost::filesystem::path);
void read_stream (std::istream &);
- virtual ~Document ();
-
+ std::string root_name () const {
+ return _root_name;
+ }
+
private:
void take_root_node ();
BOOST_CHECK (!document.optional_bool_child("G"));
- BOOST_CHECK_EQUAL (document.node_children("H/I").size(), 2);
- BOOST_CHECK_EQUAL (document.node_children("H/I").front()->content(), "testing");
- BOOST_CHECK_EQUAL (document.node_children("H/I").back()->content(), "more testing");
+ list<shared_ptr<cxml::Node> > h = document.node_children ("H");
+ BOOST_CHECK_EQUAL (h.size(), 1);
+ BOOST_CHECK_EQUAL (h.front()->node_children("I").size(), 2);
+ BOOST_CHECK_EQUAL (h.front()->node_children("I").front()->content(), "testing");
+ BOOST_CHECK_EQUAL (h.front()->node_children("I").back()->content(), "more testing");
- BOOST_CHECK_EQUAL (document.string_child("J/K"), "jim");
- BOOST_CHECK (!document.optional_bool_child("G"));
+ BOOST_CHECK_EQUAL (document.node_children("J").size(), 1);
+ BOOST_CHECK_EQUAL (document.node_children("J").front()->node_children("K").size(), 1);
+ BOOST_CHECK_EQUAL (document.node_children("J").front()->node_children("K").front()->content(), "jim");
}