Use exceptions to report calls to Node with _node == 0.
[libcxml.git] / src / cxml.cc
index 77770f93b0fb7ad943de5863cc72a151d79db518..d3ec9e7fd95f6a27efa9a6eeae6543345cc57da9 100644 (file)
@@ -43,7 +43,9 @@ cxml::Node::Node (xmlpp::Node* node)
 string
 cxml::Node::name () const
 {
-       assert (_node);
+       if (!_node) {
+               throw Error ("No node to read name from");
+       }
        return _node->get_name ();
 }
 
@@ -76,6 +78,9 @@ cxml::Node::optional_node_child (string name) const
 list<shared_ptr<cxml::Node> >
 cxml::Node::node_children () const
 {
+       if (!_node) {
+               throw Error ("No node to read children from");
+       }
        xmlpp::Node::NodeList c = _node->get_children ();
 
        list<shared_ptr<cxml::Node> > n;
@@ -220,7 +225,7 @@ cxml::Node::content () const
         xmlpp::Node::NodeList c = _node->get_children ();
        for (xmlpp::Node::NodeList::const_iterator i = c.begin(); i != c.end(); ++i) {
                xmlpp::ContentNode const * v = dynamic_cast<xmlpp::ContentNode const *> (*i);
-               if (v) {
+               if (v && dynamic_cast<xmlpp::TextNode const *>(v)) {
                        content += v->get_content ();
                }
        }