wi_runtime_instance_t * wi_plist_instance_for_string(wi_string_t *string) { wi_runtime_instance_t *instance; xmlDocPtr doc; doc = xmlReadMemory(wi_string_cstring(string), wi_string_length(string), NULL, NULL, 0); if(!doc) { wi_error_set_libxml2_error(); return NULL; } instance = _wi_plist_instance_for_document(doc); xmlFreeDoc(doc); return instance; }
struct iio_context * xml_create_context_mem(const char *xml, size_t len) { struct iio_context *ctx; xmlDoc *doc; LIBXML_TEST_VERSION; doc = xmlReadMemory(xml, (int) len, NULL, NULL, XML_PARSE_DTDVALID); if (!doc) { ERROR("Unable to parse XML file\n"); return NULL; } ctx = iio_create_xml_context_helper(doc); xmlFreeDoc(doc); xmlCleanupParser(); return ctx; }
feed parser::parse_buffer(const char * buffer, size_t size, const char * url) { doc = xmlReadMemory(buffer, size, url, NULL, XML_PARSE_RECOVER | XML_PARSE_NOERROR | XML_PARSE_NOWARNING); if (doc == NULL) { throw exception(_("could not parse buffer")); } xmlNode* root_element = xmlDocGetRootElement(doc); feed f = parse_xmlnode(root_element); if (doc->encoding) { f.encoding = (const char *)doc->encoding; } LOG(LOG_INFO, "parser::parse_buffer: encoding = %s", f.encoding.c_str()); return f; }
cocos2d::CCDictionary *dictionaryFromPlist(const char *pFileName){ xmlDoc *doc(0); xmlNode *root_element(0); /* * this initialize the library and check potential ABI mismatches * between the version it was compiled for and the actual shared * library used. */ LIBXML_TEST_VERSION /*parse the file and get the DOM */ // on android i seem to have to go through ccfileutils to get the data, may as well always do it unsigned long uSize(0); xmlChar * xmlBuff(cocos2d::CCFileUtils::sharedFileUtils()->getFileData(pFileName, "r", &uSize)); if (uSize) doc = xmlReadMemory((const char *)xmlBuff, uSize, "", 0, XML_PARSE_NOBLANKS); CC_SAFE_DELETE_ARRAY(xmlBuff); //could not parse the file pFileName! assert(doc); /*Get the root element node */ root_element = xmlDocGetRootElement(doc); // print_element_names(root_element, ""); cocos2d::CCDictionary *d = (cocos2d::CCDictionary *) allocValueForNode(root_element->children); d->autorelease(); /*free the document */ xmlFreeDoc(doc); /* *Free the global variables that may *have been allocated by the parser. */ xmlCleanupParser(); return d; }
static int rtS3ReadXmlFromMemory(PRTS3TMPMEMCHUNK pChunk, const char* pszRootElement, xmlDocPtr *ppDoc, xmlNodePtr *ppCur) { *ppDoc = xmlReadMemory(pChunk->pszMem, (int)pChunk->cSize, "", "ISO-8859-1", XML_PARSE_NOBLANKS | XML_PARSE_NONET); if (*ppDoc == NULL) return VERR_PARSE_ERROR; *ppCur = xmlDocGetRootElement(*ppDoc); if (*ppCur == NULL) { xmlFreeDoc(*ppDoc); return VERR_PARSE_ERROR; } if (xmlStrcmp((*ppCur)->name, (const xmlChar *) pszRootElement)) { xmlFreeDoc(*ppDoc); return VERR_PARSE_ERROR; } return VINF_SUCCESS; }
char *filter(char *str, Regexfilter *filterList) { xmlDocPtr doc; xmlNodePtr item_node, title_node; xmlChar *xmlbuff, *title_content; int buffersize; doc = xmlReadMemory(str, strlen(str), "noname.xml", NULL, 0); if (doc == NULL) { fprintf(stderr, "Failed to parse document\n"); return; } item_node = feed_first_item(doc); /* loop through items */ while (item_node != NULL) { title_node = xmlFirstElementChild(item_node); title_content = xmlNodeGetContent(title_node); if (!pattern_check((char *)title_content, filterList)) { /* remove <item> node and leftover space*/ feed_remove_node(&item_node); feed_remove_node(&item_node); } item_node = xmlNextElementSibling(item_node); } /* * Convert rss doc to string * and return. */ xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize,1); xmlFreeDoc(doc); return xmlbuff; }
/** Provides to parse a configuration file */ static void check_configuration () { int fsize; gchar *file; xmlDocPtr doc; file = read_configuration (&fsize); doc = xmlReadMemory (file, fsize, NULL, NULL, XML_PARSE_NOBLANKS); if (doc == NULL) { g_warning ("Unable to read configuration"); } else { build_hierarchy_tree_from_xml (doc); xmlFreeDoc (doc); } g_free (file); }
// // readString: // bool XMLTableParser::readString(const std::string &inString, xmlNode *node ){ reset(); // read document from string _document = xmlReadMemory(inString.c_str(), inString.size(), NULL, NULL, 0); if (_document == NULL) { throw Exception("XMLTableParser::readString()","Could not parse %s XML string",inString.c_str()); } // get start node if(node) _rootElement = node; else _rootElement = xmlDocGetRootElement(_document); return _readDocument(); }
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; }
OSyncXMLFormat *osync_xmlformat_parse(const char *buffer, unsigned int size, OSyncError **error) { OSyncXMLFormat *xmlformat = NULL; xmlNodePtr cur = NULL; osync_trace(TRACE_ENTRY, "%s(%p, %i, %p)", __func__, buffer, size, error); osync_assert(buffer); xmlformat = osync_try_malloc0(sizeof(OSyncXMLFormat), error); if(!xmlformat) { osync_trace(TRACE_EXIT_ERROR, "%s: %s" , __func__, osync_error_print(error)); return NULL; } xmlformat->doc = xmlReadMemory(buffer, size, NULL, NULL, XML_PARSE_NOBLANKS); if(!xmlformat->doc) { g_free(xmlformat); osync_error_set(error, OSYNC_ERROR_GENERIC, "Could not parse XML."); osync_trace(TRACE_EXIT_ERROR, "%s: %s" , __func__, osync_error_print(error)); return NULL; } xmlformat->ref_count = 1; xmlformat->first_child = NULL; xmlformat->last_child = NULL; xmlformat->child_count = 0; xmlformat->doc->_private = xmlformat; cur = xmlDocGetRootElement(xmlformat->doc); cur = cur->children; while (cur != NULL) { OSyncXMLField *xmlfield = osync_xmlfield_new_node(xmlformat, cur, error); if(!xmlfield) { osync_xmlformat_unref(xmlformat); osync_trace(TRACE_EXIT_ERROR, "%s: %s" , __func__, osync_error_print(error)); return NULL; } cur = cur->next; } osync_trace(TRACE_EXIT, "%s: %p", __func__, xmlformat); return xmlformat; }
void cepgdata2xmltv::LoadXSLT() { if (pxsltStylesheet) return; xmlSetGenericErrorFunc(NULL,tvmGenericErrorFunc); xmlSubstituteEntitiesDefault (1); xmlLoadExtDtdDefaultValue = 1; xmlSetExternalEntityLoader(xmlMyExternalEntityLoader); exsltRegisterAll(); if ((sxmlDoc = xmlReadMemory (xsl, sizeof(xsl), NULL,NULL,0)) != NULL) { pxsltStylesheet=xsltParseStylesheetDoc(sxmlDoc); if (!pxsltStylesheet) { esyslog("can't parse stylesheet"); xmlFreeDoc (sxmlDoc); sxmlDoc=NULL; } } }
value v2v_xml_parse_memory (value xmlv) { CAMLparam1 (xmlv); CAMLlocal1 (docv); xmlDocPtr doc; /* For security reasons, call xmlReadMemory (not xmlParseMemory) and * pass XML_PARSE_NONET. See commit 845daded5fddc70f. */ doc = xmlReadMemory (String_val (xmlv), caml_string_length (xmlv), NULL, NULL, XML_PARSE_NONET); if (doc == NULL) caml_invalid_argument ("parse_memory: unable to parse XML from libvirt"); docv = caml_alloc_custom (&doc_custom_operations, sizeof (xmlDocPtr), 0, 1); Doc_val (docv) = doc; CAMLreturn (docv); }
/** * Simple example to parse a file called "file.xml", * walk down the DOM, and print the name of the * xml elements nodes. */ int main(int argc, char **argv) { xmlDoc *doc = NULL; xmlNode *root_element = NULL; /* if (argc != 2) return(1); */ /* * this initialize the library and check potential ABI mismatches * between the version it was compiled for and the actual shared * library used. */ LIBXML_TEST_VERSION /*parse the file and get the DOM */ doc = xmlReadMemory("<request type=\"hello\"><item name=\"world\"/></request>", strlen("<request type=\"hello\"><item name=\"world\"/></request>"), "noname.xml", NULL, 0); if (doc == NULL) { printf("error: could not parse file %s\n", argv[1]); } /*Get the root element node */ root_element = xmlDocGetRootElement(doc); printf("Root element type = %s\n", xmlGetProp(root_element, "type")); print_element_names(root_element); /*free the document */ xmlFreeDoc(doc); /* *Free the global variables that may *have been allocated by the parser. */ xmlCleanupParser(); return 0; }
/** * empathy_plist_parse_from_memory: * @data: memory location containing XML plist data to parse * @len: length in bytes of the string to parse * * Parses the XML plist file stored in @data which length is @len * bytes. If an error occurs during the parsing, * empathy_plist_parse_from_memory() will return NULL. * * Returns: NULL on error, a newly allocated * #GValue otherwise. Free it using tp_g_value_slice_free() */ GValue * empathy_plist_parse_from_memory (const char *data, gsize len) { xmlDoc *doc = NULL; xmlNode *root_element = NULL; GValue *parsed_doc; doc = xmlReadMemory (data, len, "noname.xml", NULL, 0); if (doc == NULL) { return NULL; } root_element = xmlDocGetRootElement (doc); parsed_doc = empathy_plist_parse (root_element); xmlFreeDoc (doc); return parsed_doc; }
void parse_xml_buffer(const char *url, const char *buffer, int size, struct dive_table *table, GError **error) { xmlDoc *doc; target_table = table; doc = xmlReadMemory(buffer, size, url, NULL, 0); if (!doc) { fprintf(stderr, _("Failed to parse '%s'.\n"), url); parser_error(error, _("Failed to parse '%s'"), url); return; } reset_all(); dive_start(); #ifdef XSLT doc = test_xslt_transforms(doc, error); #endif traverse(xmlDocGetRootElement(doc)); dive_end(); xmlFreeDoc(doc); }
bool RelaxNGValidator::ValidateEncoded(const std::wstring& filename, const std::string& document) const { TIMER_ACCRUE(xml_validation); if (!m_Schema) { LOGERROR("RelaxNGValidator: No grammar loaded"); return false; } xmlDocPtr doc = xmlReadMemory(document.c_str(), (int)document.size(), utf8_from_wstring(filename).c_str(), NULL, XML_PARSE_NONET); if (doc == NULL) { LOGERROR("RelaxNGValidator: Failed to parse document '%s'", utf8_from_wstring(filename).c_str()); return false; } bool ret = ValidateEncoded(doc); xmlFreeDoc(doc); return ret; }
static gchar *get_uploadid (const char *xml, size_t xml_len) { xmlDocPtr doc; xmlXPathContextPtr ctx; xmlXPathObjectPtr uploadid_xp; xmlNodeSetPtr nodes; gchar *uploadid = NULL; doc = xmlReadMemory (xml, xml_len, "", NULL, 0); ctx = xmlXPathNewContext (doc); xmlXPathRegisterNs (ctx, (xmlChar *) "s3", (xmlChar *) "http://s3.amazonaws.com/doc/2006-03-01/"); uploadid_xp = xmlXPathEvalExpression ((xmlChar *) "//s3:UploadId", ctx); if (!uploadid_xp) { LOG_err (FIO_LOG, "S3 returned incorrect XML !"); xmlXPathFreeContext (ctx); xmlFreeDoc (doc); return NULL; } nodes = uploadid_xp->nodesetval; if (!nodes) { LOG_err (FIO_LOG, "S3 returned incorrect XML !"); xmlXPathFreeObject (uploadid_xp); xmlXPathFreeContext (ctx); xmlFreeDoc (doc); return NULL; } if (!nodes || nodes->nodeNr < 1) { uploadid = NULL; } else { uploadid = (char *) xmlNodeListGetString (doc, nodes->nodeTab[0]->xmlChildrenNode, 1); } xmlXPathFreeObject (uploadid_xp); xmlXPathFreeContext (ctx); xmlFreeDoc (doc); return uploadid; }
static bool parse_manifest(struct uae_prefs *p, unzFile uz, const char *manifest) { bool bResult = false; char buffer[MAX_MANIFEST_ENTRY]; xmlDocPtr doc = xmlReadMemory(manifest, strlen(manifest), NULL, NULL, 0);; if(doc != NULL) { xmlNode *root_element = xmlDocGetRootElement(doc); xmlNode *rp9 = get_node(root_element, "rp9"); if(rp9 != NULL) { xmlNode *app = get_node(rp9, "application"); if(app != NULL) { int rom = -1; xmlNode *tmp = get_node(app, "description"); if(tmp != NULL && get_value(tmp, "systemrom", buffer, MAX_MANIFEST_ENTRY)) rom = atoi(buffer); tmp = get_node(app, "configuration"); if(tmp != NULL && get_value(tmp, "system", buffer, MAX_MANIFEST_ENTRY)) { set_default_system(p, buffer, rom); parse_compatibility(p, tmp); parse_ram(p, tmp); parse_clip(p, tmp); parse_peripheral(p, tmp); parse_boot(p, tmp); extract_media(p, uz, app); bResult = true; } } } xmlFreeDoc(doc); } return bResult; }
TVDB_API int tvdb_parse_rating(const tvdb_buffer_t *xml, const char *url, float *rating) { xmlDoc *doc=NULL; xmlNode *node=NULL; xmlNode *elem=NULL; xmlNode *data=NULL; int result = TVDB_E_PARSE_RATING_XML; char *tmp=NULL; if(xml == NULL) { return TVDB_E_PARSE_RATING_XML; } *rating = 0.0; doc = xmlReadMemory(xml->memory, xml->size, url, 0, 0); node = xmlDocGetRootElement(doc); if (node != NULL && node->type == XML_ELEMENT_NODE && !xmlStrcmp(node->name, (const xmlChar *)"Data")) { for (elem = node->children; elem; elem = elem->next) { if (elem->type == XML_ELEMENT_NODE && !xmlStrcmp(elem->name, (const xmlChar *)"Series")) { for (data = elem->children; data; data = data->next) { if (!xmlStrcmp(data->name, (const xmlChar *)"Rating")) { if ((tmp = (char*) xmlNodeGetContent(data))) { *rating = atof(tmp); xmlFree(tmp); if(*rating != 0.0) { result = TVDB_OK; } } } } } } } xmlFreeDoc(doc); return result; }
xmlDocPtr TwsXml::nextXmlDoc() { xmlDocPtr doc = NULL; if( file == NULL ) { return doc; } /* This is ugly code. If we will rewrite it to use xml push parser then we could avoid resize_buf(), memmove() and even find_form_feed(). */ int jump_ff = 0; char *cp = buf; int tmp_len = buf_len; while( true ) { int ff = find_form_feed(cp, tmp_len); if( ff < tmp_len ) { cp += ff; jump_ff = 1; break; } cp += tmp_len; if( (buf_len + CHUNK_SIZE) >= buf_size ) { resize_buf(); cp = buf + buf_len; } tmp_len = fread(cp, 1, CHUNK_SIZE, (FILE*)file); if( tmp_len <=0 ) { jump_ff = 0; break; } buf_len += tmp_len; } doc = xmlReadMemory( buf, cp-buf, "URL", NULL, 0 ); buf_len -= cp - buf + jump_ff; memmove( buf, cp + jump_ff, buf_len ); return doc; }
void midgard_core_object_get_xml_doc( MidgardConnection *mgd, const gchar *xml, xmlDoc **doc, xmlNode **root_node) { g_assert(*doc == NULL); g_assert(*root_node == NULL); if(xml == NULL) g_warning("Creating Midgard Object from xml requires xml." "NULL passed"); LIBXML_TEST_VERSION /* midgard_object.xml is a dummy base URL in this case */ *doc = xmlReadMemory(xml, strlen(xml), "midgard_object.xml", NULL, 0); if(!*doc) { g_warning("Can not parse given xml"); return; } *root_node = xmlDocGetRootElement(*doc); if(!*root_node) { g_warning("Can not find root element for given xml"); xmlFreeDoc(*doc); doc = NULL; return; } /* TODO : Get version from href and fail if invalid version exists */ if(!g_str_equal((*root_node)->ns->href, MIDGARD_OBJECT_HREF) || !g_str_equal((*root_node)->name, "midgard_object")) { g_warning("Skipping invalid midgard_object xml"); xmlFreeDoc(*doc); *doc = NULL; *root_node = NULL; return; } }
static void process_video_search_result (const gchar *xml_result, gpointer user_data) { xmlDocPtr doc; xmlNodePtr node; GList *video_list = NULL; GVimeoVideoSearchData *data = (GVimeoVideoSearchData *) user_data; doc = xmlReadMemory (xml_result, xmlStrlen ((xmlChar *) xml_result), NULL, NULL, XML_PARSE_RECOVER | XML_PARSE_NOBLANKS); node = xmlDocGetRootElement (doc); /* Check result is ok */ if (!node || !result_is_correct (node)) { data->search_cb (data->vimeo, NULL, data->user_data); } else { node = node->xmlChildrenNode; /* Now we're at "video pages" node */ node = node->xmlChildrenNode; while (node) { video_list = g_list_prepend (video_list, get_video (node)); node = node->next; } video_list = g_list_reverse (video_list); data->search_cb (data->vimeo, video_list, data->user_data); g_list_free_full (video_list, (GDestroyNotify) g_hash_table_unref); } g_slice_free (GVimeoVideoSearchData, data); xmlFreeDoc (doc); }
/* * call-seq: * read_memory(string, url, encoding, options) * * Create a new document from a String */ static VALUE read_memory( VALUE klass, VALUE string, VALUE url, VALUE encoding, VALUE options ) { const char * c_buffer = StringValuePtr(string); const char * c_url = (url == Qnil) ? NULL : StringValuePtr(url); const char * c_enc = (encoding == Qnil) ? NULL : StringValuePtr(encoding); int len = NUM2INT(rb_funcall(string, rb_intern("length"), 0)); xmlInitParser(); xmlDocPtr doc = xmlReadMemory(c_buffer, len, c_url, c_enc, NUM2INT(options)); if(doc == NULL) { xmlFreeDoc(doc); rb_raise(rb_eRuntimeError, "Couldn't create a document"); return Qnil; } return Nokogiri_wrap_xml_document(klass, doc); }
static void testDocumentRangeByte1(xmlParserCtxtPtr ctxt, char *document, int len, char *data, int forbid1, int forbid2) { int i; xmlDocPtr res; for (i = 0;i <= 0xFF;i++) { lastError = 0; xmlCtxtReset(ctxt); data[0] = i; res = xmlReadMemory(document, len, "test", NULL, 0); if ((i == forbid1) || (i == forbid2)) { if ((lastError == 0) || (res != NULL)) fprintf(stderr, "Failed to detect invalid char for Byte 0x%02X: %c\n", i, i); } else if ((i == '<') || (i == '&')) { if ((lastError == 0) || (res != NULL)) fprintf(stderr, "Failed to detect illegal char %c for Byte 0x%02X\n", i, i); } else if (((i < 0x20) || (i >= 0x80)) && (i != 0x9) && (i != 0xA) && (i != 0xD)) { if ((lastError != XML_ERR_INVALID_CHAR) && (res != NULL)) fprintf(stderr, "Failed to detect invalid char for Byte 0x%02X\n", i); } else if (res == NULL) { fprintf(stderr, "Failed to parse valid char for Byte 0x%02X : %c\n", i, i); } if (res != NULL) xmlFreeDoc(res); } }
bool XMLSchema::validate(xmlDocPtr doc, const std::string& xsd) { xmlParserOption parserOption(XML_PARSE_NONET); xmlDocPtr schemaDoc = xmlReadMemory(xsd.c_str(), xsd.size(), NULL, NULL, parserOption); xmlSchemaParserCtxtPtr parserCtxt = xmlSchemaNewDocParserCtxt(schemaDoc); xmlSchemaSetParserStructuredErrors(parserCtxt, &OCISchemaParserStructuredErrorHandler, m_global_context); xmlSchemaPtr schema = xmlSchemaParse(parserCtxt); xmlSchemaValidCtxtPtr validCtxt = xmlSchemaNewValidCtxt(schema); xmlSchemaSetValidErrors(validCtxt, &OCISchemaValidityError, &OCISchemaValidityDebug, m_global_context); bool valid = (xmlSchemaValidateDoc(validCtxt, doc) == 0); xmlFreeDoc(schemaDoc); xmlSchemaFreeParserCtxt(parserCtxt); xmlSchemaFree(schema); xmlSchemaFreeValidCtxt(validCtxt); return valid; }
xmlDocPtr XMLSchema::init(const std::string& xml, const std::string& xsd) { xmlParserOption parserOption(XML_PARSE_NONET); LIBXML_TEST_VERSION xmlSetGenericErrorFunc(m_global_context, (xmlGenericErrorFunc)&OCISchemaGenericErrorHandler); xmlSetStructuredErrorFunc(m_global_context, (xmlStructuredErrorFunc)&OCISchemaStructuredErrorHandler); xmlDocPtr doc = xmlReadMemory(xml.c_str(), xml.size(), NULL, NULL, parserOption); if (xsd.size() && !validate(doc, xsd)) { xmlFreeDoc(doc); doc = NULL; std::cerr << "Document did not validate against schema." << std::endl; } return doc; }
/*Returns all the entries from the feed */ GSList * gdata_entries_new_from_xml (const gchar *feed_xml, const gint length) { GSList *list; xmlNodePtr cur; xmlDocPtr doc; list = NULL; g_return_val_if_fail(feed_xml != NULL && *feed_xml != '\0', NULL); doc = xmlReadMemory (feed_xml, strlen(feed_xml), "feed.xml", NULL, 0); if (doc == NULL) return NULL; cur = xmlDocGetRootElement (doc); if (cur == NULL) { xmlFree (doc); } cur = cur->xmlChildrenNode; while (cur != NULL) { if (!xmlStrcmp (cur->name, (xmlChar *)"entry")) { list = g_slist_prepend (list, gdata_entry_new_from_xmlptr (doc, cur)); } cur = cur->next; } /* Free them */ xmlFreeDoc (doc); xmlFreeNode (cur); if (list == NULL) g_slist_free (list); return list; }
int send_lote(LOTE *lote, char *URL, int ambiente, int cuf, EVP_PKEY *key, X509 *cert, char *msg){ char *response, *status; int cStat, rc; xmlDocPtr doc; char *xml = gen_lote_xml(lote, key, cert); response = send_sefaz(SEFAZ_NFE_AUTORIZACAO, URL, ambiente, cuf, xml, key, cert); if(response == NULL){ strcpy(msg, "Sem resposta do SEFAZ, tente novamente"); return -ESEFAZ; } doc = xmlReadMemory(response, strlen(response), "noname.xml", NULL, 0); status = get_xml_element(doc, "nfe:cStat"); if(status == NULL){ return -ESEFAZ; } cStat = atoi(status); char *motivo = get_xml_element(doc, "nfe:xMotivo"); if(motivo == NULL){ return -ESEFAZ; } strcpy(msg, motivo); char *nRec = get_xml_element(doc, "nfe:nRec"); fprintf(stdout, "Lote: %s\n", nRec); lote->recibo = strdup(nRec); lote->xml_response = strdup(response); xmlFree(motivo); xmlFree(status); xmlFree(nRec); if(rc){ sprintf(msg, "Erro ao salvar lote\nNúmero de recibo: %s", nRec); return -ESQL; } return cStat; }
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); }
int parse_tag_index(const char * document, Array * a, time_t * updated) { int rc = TAG_INDEX_OK; if (document && a) { xmlDocPtr doc = xmlReadMemory(document, strlen(document), "", NULL, XML_PARSE_COMPACT); if (doc) { xmlXPathContextPtr ctx = xmlXPathNewContext(doc); xmlXPathRegisterNs(ctx, BAD_CAST "atom", BAD_CAST ATOM); xmlXPathRegisterNs(ctx, BAD_CAST "classifier", BAD_CAST CLASSIFIER); if (updated) { *updated = get_element_value_time(ctx, "/atom:feed/atom:updated/text()"); } xmlXPathObjectPtr xp = xmlXPathEvalExpression(BAD_CAST "/atom:feed/atom:entry/atom:link[@rel = 'http://peerworks.org/classifier/training']", ctx); if (!xmlXPathNodeSetIsEmpty(xp->nodesetval)) { int i; for (i = 0; i < xp->nodesetval->nodeNr; i++) { xmlNodePtr node = xp->nodesetval->nodeTab[i]; char *url = xmlGetProp(node, BAD_CAST "href"); arr_add(a, url); } xmlXPathFreeObject(xp); xmlXPathFreeContext(ctx); xmlFreeDoc(doc); } else { info("No tags in tag index"); } } else { error("Could not parse tag index: %s", document); rc = TAG_INDEX_FAIL; } } return rc; }