dup (Nokogiri::XML::Document)

    /*
     * call-seq:
     *  dup
     *
     * Copy this Document.  An optional depth may be passed in, but it defaults
     * to a deep copy.  0 is a shallow copy, 1 is a deep copy.
     */
    static VALUE duplicate_node(int argc, VALUE *argv, VALUE self)
    {
      VALUE level;

      if(rb_scan_args(argc, argv, "01", &level) == 0)
        level = INT2NUM(1);

      xmlDocPtr doc, dup;
      Data_Get_Struct(self, xmlDoc, doc);

      dup = xmlCopyDoc(doc, NUM2INT(level));
      if(dup == NULL) return Qnil;

      dup->type = doc->type;
      return Nokogiri_wrap_xml_document(RBASIC(self)->klass, dup);
    }