void xml_throw_unless(bool condition) { if (!condition) { char const *message = "unknown XML error"; xmlErrorPtr xmlErr = xmlGetLastError(); if (xmlErr && xmlErr->message) { message = xmlErr->message; } error err("%s", message); xmlResetLastError(); throw err; } }
/* call-seq: * XPath::Expression.new(expression) -> XPath::Expression * * Compiles an XPatch expression. This improves performance * when an XPath expression is called multiple times. * * doc = XML::Document.string('<header><first>hi</first></header>') * expr = XPath::Expression.new('//first') * nodes = doc.find(expr) */ static VALUE rxml_xpath_expression_initialize(VALUE self, VALUE expression) { xmlXPathCompExprPtr compexpr = xmlXPathCompile((const xmlChar*)StringValueCStr(expression)); if (compexpr == NULL) { xmlErrorPtr xerror = xmlGetLastError(); rxml_raise(xerror); } DATA_PTR( self) = compexpr; return self; }
static int parse_ticket_state(struct ticket_config *tk, FILE *p) { int rv = 0; GString *input = NULL; char line[CHUNK_SIZE]; xmlDocPtr doc = NULL; xmlErrorPtr errptr; int opts = XML_PARSE_COMPACT | XML_PARSE_NONET; /* skip first two lines of output */ if (fgets(line, CHUNK_SIZE-1, p) == NULL || fgets(line, CHUNK_SIZE-1, p) == NULL) { tk_log_error("crm_ticket xml output empty"); rv = ENODATA; goto out; } input = g_string_sized_new(CHUNK_SIZE); if (!input) { log_error("out of memory"); rv = -1; goto out; } while (fgets(line, CHUNK_SIZE-1, p) != NULL) { if (!g_string_append(input, line)) { log_error("out of memory"); rv = -1; goto out; } } doc = xmlReadDoc((const xmlChar *) input->str, NULL, NULL, opts); if (doc == NULL) { errptr = xmlGetLastError(); if (errptr) { tk_log_error("crm_ticket xml parse failed (domain=%d, level=%d, code=%d): %s", errptr->domain, errptr->level, errptr->code, errptr->message); } else { tk_log_error("crm_ticket xml parse failed"); } rv = -EINVAL; goto out; } rv = save_attributes(tk, doc); out: if (doc) xmlFreeDoc(doc); if (input) g_string_free(input, TRUE); return rv; }
const int BEXMLReaderInterface::last_error ( const int default_error ) { xmlErrorPtr xml_error = xmlGetLastError(); // don't crash if there's no xml_error int error; if ( xml_error ) { error = xml_error->code; } else { error = default_error; } return error; }
int oscap_xml_save_filename(const char *filename, xmlDocPtr doc) { xmlOutputBufferPtr buff; int xmlCode; if (strcmp(filename, "-") == 0) { xmlCode = xmlSaveFormatFileEnc(filename, doc, "UTF-8", 1); } else { int fd = open(filename, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); if (fd < 0) { oscap_seterr(OSCAP_EFAMILY_GLIBC, "%s '%s'", strerror(errno), filename); xmlFreeDoc(doc); return -1; } buff = xmlOutputBufferCreateFd(fd, NULL); if (buff == NULL) { close(fd); oscap_setxmlerr(xmlGetLastError()); oscap_dlprintf(DBG_W, "xmlOutputBufferCreateFile() failed.\n"); xmlFreeDoc(doc); return -1; } xmlCode = xmlSaveFormatFileTo(buff, doc, "UTF-8", 1); close(fd); } if (xmlCode <= 0) { oscap_setxmlerr(xmlGetLastError()); oscap_dlprintf(DBG_W, "No bytes exported: xmlCode: %d.\n", xmlCode); } return (xmlCode >= 1) ? 1 : -1; }
void wi_error_set_libxml2_error(void) { wi_error_t *error; xmlErrorPtr xml_error; xml_error = xmlGetLastError(); error = _wi_get_error(); error->domain = WI_ERROR_DOMAIN_REGEX; error->code = xml_error->code; wi_release(error->string); error->string = wi_string_init_with_cstring(wi_string_alloc(), xml_error->message); wi_string_delete_surrounding_whitespace(error->string); }
const struct xccdf_version_info* xccdf_detect_version_parser(xmlTextReaderPtr reader) { const struct xccdf_version_info *mapptr; const char* namespace_uri = (const char*)xmlTextReaderConstNamespaceUri(reader); if (!namespace_uri) { oscap_setxmlerr(xmlGetLastError()); return NULL; } mapptr = _namespace_get_xccdf_version_info(namespace_uri); if (mapptr == NULL) oscap_seterr(OSCAP_EFAMILY_XML, "This is not known XCCDF namespace: %s.", namespace_uri); return mapptr; }
/*! * \brief Parse an xml file from a filename given in Dia's/GLib's filename encoding * * @param filename A file to parse. On win32 the filename encoding is utf-8 since GLib 2.6 * @param ctx If something goes wrong during parsing ctx will include according messages * @param try_harder If set an additional attempt is done with guessed encoding * @return An XML document. * * \ingroup DiagramXmlIo */ xmlDocPtr diaXmlParseFile(const char *filename, DiaContext *ctx, gboolean try_harder) { xmlDocPtr doc; xmlErrorPtr err; doc = xmlParseFile(filename); if (!doc) { err = xmlGetLastError (); dia_context_add_message (ctx, "%s", err->message); if (err->code == XML_ERR_INVALID_CHAR && try_harder) /* fallback to temporary file with encoding approach */ doc = xmlDiaParseFile (filename, ctx); } return doc; }
int oval_definition_model_export(struct oval_definition_model *model, const char *file) { __attribute__nonnull__(model); LIBXML_TEST_VERSION; xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); if (doc == NULL) { oscap_setxmlerr(xmlGetLastError()); return -1; } oval_definition_model_to_dom(model, doc, NULL); return oscap_xml_save_filename_free(file, doc); }
void wi_error_set_libxml2_error(void) { wi_error_t *error; wi_string_t *string; xmlErrorPtr xml_error; xml_error = xmlGetLastError(); error = _wi_error_get_error(); error->domain = WI_ERROR_DOMAIN_REGEX; error->code = xml_error->code; string = wi_string_by_deleting_surrounding_whitespace(wi_string_with_cstring(xml_error->message)); wi_release(error->string); error->string = wi_retain(string); }
int xccdf_benchmark_export(struct xccdf_benchmark *benchmark, const char *file) { __attribute__nonnull__(file); LIBXML_TEST_VERSION; xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); if (doc == NULL) { oscap_setxmlerr(xmlGetLastError()); return -1; } xccdf_benchmark_to_dom(benchmark, doc, NULL, NULL); return oscap_xml_save_filename(file, doc); }
int parse_alps_output( std::string &alps_output) { xmlDocPtr doc; xmlNode *child; if ((doc = xmlReadMemory(alps_output.c_str(), alps_output.length(), "apbasil", NULL, 0)) == NULL) { char buf[MAXLINE * 4]; xmlErrorPtr pErr = xmlGetLastError(); snprintf(buf, sizeof(buf), "Failed to parse the output of alps - %s", pErr->message); log_err(-1, __func__, buf); return(ALPS_PARSING_ERROR); } if (process_element(xmlDocGetRootElement(doc)) == ALPS_QUERY_FAILURE) { xmlNode *root = xmlDocGetRootElement(doc); // Verbose debug output for ALPS_QUERY_FAILURE node error message for (child = root->children; child != NULL; child = child->next) { if (!strcmp((const char *)child->name, response_data)) { for (xmlNode *gchild = child->children; gchild != NULL; gchild = gchild->next) { if (!strcmp((const char *)gchild->name, "Message")) { snprintf(log_buffer, sizeof(log_buffer), "Failed to query ALPS: %s", (const char *)xmlNodeGetContent(gchild)); log_record(PBSEVENT_SYSTEM, 0, __func__, log_buffer); } } } } return(ALPS_QUERY_FAILURE); } xmlFreeDoc(doc); xmlMemoryDump(); return(PBSE_NONE); } /* END parse_alps_output() */
int parse_confirmation_output( char *output) { int rc = -1; xmlDocPtr doc; xmlNode *node; char *attr_val; if ((doc = xmlReadMemory(output, strlen(output), "apbasil", NULL, 0)) == NULL) { char buf[MAXLINE * 4]; xmlErrorPtr pErr = xmlGetLastError(); snprintf(buf, sizeof(buf), "Failed to parse the output of alps - %s", pErr->message); log_err(-1, __func__, buf); return(ALPS_PARSING_ERROR); } node = xmlDocGetRootElement(doc); while (node != NULL) { if (!strcmp((const char *)node->name, response_data)) { attr_val = (char *)xmlGetProp(node, (const xmlChar *)status); if (strcmp(attr_val, success)) { rc = find_error_type(node); } else rc = PBSE_NONE; free(attr_val); break; } else if (!strcmp((const char *)node->name, text_name)) node = node->next; else node = node->children; } return(rc); } /* END parse_confirmation_output() */
static ERL_NIF_TERM last_error(ErlNifEnv *env, char *fallback) { char *default_msg = (fallback) ? fallback : "Unknown"; /* This is thread safe as long as libxml2 has been compiled with * thread support (alternatively use a mutex) */ xmlErrorPtr err = xmlGetLastError(); /* Seems the useful error is in str1? */ char *err_str = (err && err->str1) ? err->str1 : (err && err->message) ? err->message : default_msg; return enif_make_tuple2(env, am_error(env), enif_make_string(env, err_str, ERL_NIF_LATIN1)); }
/** libxml error handler */ static void _xml_error_handler(void *ctx, const char *msg, ...) { xmlError *err; if(!(err = xmlGetLastError())) { NFT_LOG(L_WARNING, "libxml2 error trigger but no xmlGetLastError()"); return; } /* convert libxml error-level to loglevel */ NftLoglevel level = L_NOISY; switch (err->level) { case XML_ERR_NONE: { level = L_DEBUG; break; } case XML_ERR_WARNING: { level = L_WARNING; break; } case XML_ERR_ERROR: { level = L_ERROR; break; } case XML_ERR_FATAL: { level = L_ERROR; break; } }; va_list args; va_start(args, msg); nft_log_va(level, err->file, "libxml2", err->line, msg, args); va_end(args); }
/* * call-seq: * from_document(doc) * * Create a new RelaxNG schema from the Nokogiri::XML::Document +doc+ */ static VALUE from_document(VALUE klass, VALUE document) { xmlDocPtr doc; xmlRelaxNGParserCtxtPtr ctx; xmlRelaxNGPtr schema; VALUE errors; VALUE rb_schema; Data_Get_Struct(document, xmlDoc, doc); /* In case someone passes us a node. ugh. */ doc = doc->doc; ctx = xmlRelaxNGNewDocParserCtxt(doc); errors = rb_ary_new(); Nokogiri_install_error_catcher(errors); #ifdef HAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS xmlRelaxNGSetParserStructuredErrors( ctx, Nokogiri_error_array_pusher, (void *)errors ); #endif schema = xmlRelaxNGParse(ctx); Nokogiri_remove_error_catcher(); if(NULL == schema) { xmlErrorPtr error = xmlGetLastError(); if(error) Nokogiri_error_raise(NULL, error); else rb_raise(rb_eRuntimeError, "Could not parse document"); return Qnil; } rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema); rb_iv_set(rb_schema, "@errors", errors); return rb_schema; }
void validateXmlString(const string& xml_string) { xmlDocPtr document_ptr = xmlParseMemory(xml_string.c_str(), xml_string.size()); if(document_ptr == 0) { xmlErrorPtr error_ptr = xmlGetLastError(); if(error_ptr) { stringstream formatter; formatter << "malformed xml: " << error_ptr->message << " at line " << error_ptr->line; xmlFreeDoc(document_ptr); throw runtime_error(formatter.str()); } } xmlFreeDoc(document_ptr); }
/* * call-seq: * from_document(doc) * * Create a new Schema from the Nokogiri::XML::Document +doc+ */ static VALUE from_document(VALUE klass, VALUE document) { xmlDocPtr doc; Data_Get_Struct(document, xmlDoc, doc); // In case someone passes us a node. ugh. doc = doc->doc; xmlSchemaParserCtxtPtr ctx = xmlSchemaNewDocParserCtxt(doc); VALUE errors = rb_ary_new(); xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher); #ifdef HAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS xmlSchemaSetParserStructuredErrors( ctx, Nokogiri_error_array_pusher, (void *)errors ); #endif xmlSchemaPtr schema = xmlSchemaParse(ctx); xmlSetStructuredErrorFunc(NULL, NULL); xmlSchemaFreeParserCtxt(ctx); if(NULL == schema) { xmlErrorPtr error = xmlGetLastError(); if(error) Nokogiri_error_raise(NULL, error); else rb_raise(rb_eRuntimeError, "Could not parse document"); return Qnil; } VALUE rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema); rb_iv_set(rb_schema, "@errors", errors); return rb_schema; return Qnil; }
/* * call-seq: * read_io(io, url, encoding, options) * * Create a new document from an IO object */ static VALUE read_io( VALUE klass, VALUE io, VALUE url, VALUE encoding, VALUE options ) { const char * c_url = NIL_P(url) ? NULL : StringValuePtr(url); const char * c_enc = NIL_P(encoding) ? NULL : StringValuePtr(encoding); VALUE error_list = rb_ary_new(); VALUE document; xmlDocPtr doc; xmlResetLastError(); Nokogiri_install_error_catcher(error_list); doc = xmlReadIO( (xmlInputReadCallback)io_read_callback, (xmlInputCloseCallback)io_close_callback, (void *)io, c_url, c_enc, (int)NUM2INT(options) ); Nokogiri_remove_error_catcher(); if(doc == NULL) { xmlErrorPtr error; xmlFreeDoc(doc); error = xmlGetLastError(); if(error) rb_exc_raise(Nokogiri_wrap_xml_syntax_error((VALUE)NULL, error)); else rb_raise(rb_eRuntimeError, "Could not parse document"); return Qnil; } document = Nokogiri_wrap_xml_document(klass, doc); rb_iv_set(document, "@errors", error_list); return document; }
/* * call-seq: * read_io(io, url, encoding, options) * * Create a new document from an IO object */ static VALUE read_io( VALUE klass, VALUE io, VALUE url, VALUE encoding, VALUE options ) { const char * c_url = (url == Qnil) ? NULL : StringValuePtr(url); const char * c_enc = (encoding == Qnil) ? NULL : StringValuePtr(encoding); VALUE error_list = rb_ary_new(); xmlInitParser(); xmlResetLastError(); xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher); xmlDocPtr doc = xmlReadIO( (xmlInputReadCallback)io_read_callback, (xmlInputCloseCallback)io_close_callback, (void *)io, c_url, c_enc, NUM2INT(options) ); xmlSetStructuredErrorFunc(NULL, NULL); if(doc == NULL) { xmlFreeDoc(doc); xmlErrorPtr error = xmlGetLastError(); if(error) rb_funcall(rb_mKernel, rb_intern("raise"), 1, Nokogiri_wrap_xml_syntax_error((VALUE)NULL, error) ); else rb_raise(rb_eRuntimeError, "Could not parse document"); return Qnil; } VALUE document = Nokogiri_wrap_xml_document(klass, doc); rb_funcall(document, rb_intern("errors="), 1, error_list); return document; }
static int parse_xml_to_cache(const char *xml, int xlen, const char *cachepath, const char *cachefile) { int retc = -1; xmlDoc *doc = NULL; xmlNode *root = NULL; /* suggested ABI check */ LIBXML_TEST_VERSION doc = xmlReadMemory(xml, xlen, "xml", NULL, 0); if (doc == NULL) { xmlError *pErr = xmlGetLastError(); if (pErr == NULL) { printf("panic!\n"); exit(100); } printf("Error parsing #%d (%d,%d)\n", pErr->code, pErr->line,pErr->int2); goto cleanup; } root = xmlDocGetRootElement(doc); if (strcmp((char *) root->name, "GANGLIA_XML") != 0) { goto cleanup; } if (parse_xml_tree_to_cache(root, cachepath, cachefile) != 0) retc = 0; cleanup: xmlFreeDoc(doc); xmlCleanupParser(); return retc; }
int Document::ProcessXInclude(bool generateXIncludeNodes) { NodeMap nmap; xmlNodePtr root = xmlDocGetRootElement(xml()); find_wrappers(root, nmap); xmlResetLastError(); int substitutionCount = xmlXIncludeProcessTreeFlags(root, generateXIncludeNodes ? 0 : XML_PARSE_NOXINCNODE); prune_unchanged_wrappers(Node::xml(), nmap); for ( auto item : nmap ) { delete item.first; } if ( substitutionCount < 0 ) throw InternalError("Failed to process XInclude", xmlGetLastError()); return substitutionCount; }
static GError *gvir_config_error_new_literal(GQuark domain, gint code, const gchar *message) { xmlErrorPtr xerr = xmlGetLastError(); if (!xerr) return NULL; if (message) return g_error_new(domain, code, "%s: %s", message, xerr->message); else return g_error_new(domain, code, "%s", xerr->message); }
/* * call-seq: * read_memory(string) * * Create a new RelaxNG from the contents of +string+ */ static VALUE read_memory(VALUE klass, VALUE content) { xmlRelaxNGParserCtxtPtr ctx = xmlRelaxNGNewMemParserCtxt( (const char *)StringValuePtr(content), (int)RSTRING_LEN(content) ); xmlRelaxNGPtr schema; VALUE errors = rb_ary_new(); VALUE rb_schema; Nokogiri_install_error_catcher(errors); #ifdef HAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS xmlRelaxNGSetParserStructuredErrors( ctx, Nokogiri_error_array_pusher, (void *)errors ); #endif schema = xmlRelaxNGParse(ctx); Nokogiri_remove_error_catcher(); xmlRelaxNGFreeParserCtxt(ctx); if(NULL == schema) { xmlErrorPtr error = xmlGetLastError(); if(error) Nokogiri_error_raise(NULL, error); else rb_raise(rb_eRuntimeError, "Could not parse document"); return Qnil; } rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema); rb_iv_set(rb_schema, "@errors", errors); return rb_schema; }
/* * call-seq: * read_memory(string) * * Create a new Schema from the contents of +string+ */ static VALUE read_memory(VALUE klass, VALUE content) { xmlSchemaParserCtxtPtr ctx = xmlSchemaNewMemParserCtxt( (const char *)StringValuePtr(content), RSTRING_LEN(content) ); VALUE errors = rb_ary_new(); xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher); xmlSchemaSetParserStructuredErrors( ctx, Nokogiri_error_array_pusher, (void *)errors ); xmlSchemaPtr schema = xmlSchemaParse(ctx); xmlSetStructuredErrorFunc(NULL, NULL); xmlSchemaFreeParserCtxt(ctx); if(NULL == schema) { xmlErrorPtr error = xmlGetLastError(); if(error) rb_funcall(rb_mKernel, rb_intern("raise"), 1, Nokogiri_wrap_xml_syntax_error((VALUE)NULL, error) ); else rb_raise(rb_eRuntimeError, "Could not parse document"); return Qnil; } VALUE rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema); rb_iv_set(rb_schema, "@errors", errors); return rb_schema; }
/** * @brief parse a style definition file * @param appdata the global information structure * @param fullname absolute path of the file to read * @param fname location to store name of the object style XML file or NULL * @param name_only only parse the style name, leave all other fields empty * @return a new style pointer */ static style_t *style_parse(appdata_t *appdata, const char *fullname, xmlChar **fname, gboolean name_only) { xmlDoc *doc = xmlReadFile(fullname, NULL, 0); /* parse the file and get the DOM */ if(doc == NULL) { xmlErrorPtr errP = xmlGetLastError(); errorf(GTK_WIDGET(appdata->window), _("Style parsing failed:\n\n" "XML error while parsing style file\n" "%s"), errP->message); return NULL; } else { /* Get the root element node */ xmlNode *cur_node = NULL; style_t *style = NULL; for(cur_node = xmlDocGetRootElement(doc); cur_node; cur_node = cur_node->next) { if (cur_node->type == XML_ELEMENT_NODE) { if(strcasecmp((char*)cur_node->name, "style") == 0) { if(!style) { style = g_new0(style_t, 1); style->name = (char*)xmlGetProp(cur_node, BAD_CAST "name"); if(name_only) break; parse_style_node(cur_node, fname, style); style->iconP = &appdata->icon; } } else printf(" found unhandled %s\n", cur_node->name); } } xmlFreeDoc(doc); return style; } }
/*! \brief Attempts to merge model information from a data file. */ static SANE_Status _model_info_merge_file (_model_info_t *self) { xmlDocPtr doc = NULL; char *path_name = NULL; char *hex_name = NULL; require (self); hex_name = fw_name_to_hex (self->fw_name); if (!hex_name) return SANE_STATUS_NO_MEM; path_name = get_path_name (hex_name, NULL, 0); delete (hex_name); /* no longer needed */ if (!path_name) return SANE_STATUS_NO_MEM; log_data ("%s", path_name); doc = xmlReadFile (path_name, NULL, XML_PARSE_NOERROR | XML_PARSE_NOWARNING); delete (path_name); /* no longer needed */ if (doc) { _model_info_merge_data (self, xmlDocGetRootElement (doc)); xmlFreeDoc (doc); } else { xmlErrorPtr p = xmlGetLastError (); if (p) err_minor ("%s", p->message); } return SANE_STATUS_GOOD; }
VALUE rxml_xpath_to_value(xmlXPathContextPtr xctxt, xmlXPathObjectPtr xobject) { VALUE result; int type; if (xobject == NULL) { /* xmlLastError is different than xctxt->lastError. Use xmlLastError since it has the message set while xctxt->lastError does not. */ xmlErrorPtr xerror = xmlGetLastError(); rxml_raise(xerror); } switch (type = xobject->type) { case XPATH_NODESET: result = rxml_xpath_object_wrap(xctxt->doc, xobject); break; case XPATH_BOOLEAN: result = (xobject->boolval != 0) ? Qtrue : Qfalse; xmlXPathFreeObject(xobject); break; case XPATH_NUMBER: result = rb_float_new(xobject->floatval); xmlXPathFreeObject(xobject); break; case XPATH_STRING: result = rxml_new_cstr(xobject->stringval, xctxt->doc->encoding); xmlXPathFreeObject(xobject); break; default: xmlXPathFreeObject(xobject); rb_raise(rb_eTypeError, "can't convert XPath object of type %d to Ruby value", type ); } return result; }
static void geonames_request_cb(net_result_t *result, gpointer data) { GError *err; request_cb_t *context = (request_cb_t*)data; g_message("asynchronous request callback."); g_return_if_fail(context && context->cb); if(!result->code) { /* feed this into the xml parser */ xmlDoc *doc = NULL; LIBXML_TEST_VERSION; g_message("Got: %s", result->data.ptr); g_message("analysing..."); /* parse the file and get the DOM */ if((doc = xmlReadMemory(result->data.ptr, result->data.len, NULL, NULL, 0)) == NULL) { xmlErrorPtr errP = xmlGetLastError(); err = g_error_new(MAEP_NET_IO_ERROR, 0, "While parsing:\n%s", errP->message); context->cb(context->obj, NULL, err); g_error_free(err); } else { g_message("XML parsed without error"); GSList *list = geonames_parse_doc(doc); context->cb(context->obj, list, (GError*)0); } } else { err = g_error_new(MAEP_NET_IO_ERROR, 0, "Geonames download failed!"); context->cb(context->obj, NULL, err); g_error_free(err); } g_free(context); }
/* * call-seq: * context.find("xpath") -> XML::XPath::Object * * Find nodes matching the specified XPath expression */ static VALUE rxml_xpath_context_find(VALUE self, VALUE xpath_expr) { xmlXPathContextPtr xctxt; xmlXPathObjectPtr xobject; xmlXPathCompExprPtr xcompexpr; VALUE result; Data_Get_Struct(self, xmlXPathContext, xctxt); if (TYPE(xpath_expr) == T_STRING) { VALUE expression = rb_check_string_type(xpath_expr); xobject = xmlXPathEval((xmlChar*) StringValueCStr(expression), xctxt); } else if (rb_obj_is_kind_of(xpath_expr, cXMLXPathExpression)) { Data_Get_Struct(xpath_expr, xmlXPathCompExpr, xcompexpr); xobject = xmlXPathCompiledEval(xcompexpr, xctxt); } else { rb_raise(rb_eTypeError, "Argument should be an intance of a String or XPath::Expression"); } if (xobject == NULL) { /* xmlLastError is different than xctxt->lastError. Use xmlLastError since it has the message set while xctxt->lastError does not. */ xmlErrorPtr xerror = xmlGetLastError(); rxml_raise(xerror); } result = rxml_xpath_object_wrap(xobject); rb_iv_set(result, "@context", self); return result; }