/*
* call-seq:
* add_child(node)
*
* Add +node+ as a child of this node. Returns the new child node.
*/
static VALUE add_child(VALUE self, VALUE child)
{
xmlNodePtr node, parent, new_child;
Data_Get_Struct(child, xmlNode, node);
Data_Get_Struct(self, xmlNode, parent);
xmlUnlinkNode(node) ;
if(!(new_child = xmlAddChild(parent, node)))
rb_raise(rb_eRuntimeError, "Could not add new child");
// the child was a text node that was coalesced. we need to have the object
// point at SOMETHING, or we'll totally bomb out.
if (new_child != node)
DATA_PTR(child) = new_child ;
return Nokogiri_wrap_xml_node(new_child);
}