    /*
     * call-seq:
     *   validate(document)
     *
     * Validate +document+ returning a list of errors
     */
    static VALUE validate(VALUE self, VALUE document)
    {
      xmlDocPtr doc;
      xmlDtdPtr dtd;
      xmlValidCtxtPtr ctxt;
      VALUE error_list;

      Data_Get_Struct(self, xmlDtd, dtd);
      Data_Get_Struct(document, xmlDoc, doc);
      error_list = rb_ary_new();

      ctxt = xmlNewValidCtxt();

      xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);

      xmlValidateDtd(ctxt, doc, dtd);

      xmlSetStructuredErrorFunc(NULL, NULL);

      xmlFreeValidCtxt(ctxt);

      return error_list;
    }