/*
 * call-seq:
 *  add_namespace_definition(prefix, href)
 *
 * Adds a namespace definition with +prefix+ using +href+
 */
static VALUE add_namespace_definition(VALUE self, VALUE prefix, VALUE href)
{
  xmlNodePtr node;
  Data_Get_Struct(self, xmlNode, node);


  xmlNsPtr ns = xmlNewNs(
      node,
      (const xmlChar *)StringValuePtr(href),
      (const xmlChar *)(prefix == Qnil ? NULL : StringValuePtr(prefix))
  );

  if(!ns) {
    ns = xmlSearchNs(
        node->doc,
        node,
        (const xmlChar *)(prefix == Qnil ? NULL : StringValuePtr(prefix))
    );
  }

  if(Qnil == prefix) xmlSetNs(node, ns);

  return Nokogiri_wrap_xml_namespace(node->doc, ns);
}