Movatterモバイル変換


[0]ホーム

URL:


API Overview
Docs
API: easyAPI: multiAPI: shareAPI: URLAPI: WebSocketEnvironment varsErrorsExamplesSecuritySymbolsTutorial
easy setopt optionseasy getinfo optionsmulti setopt optionsTLS options
Functions
All functionscurl_easy_getinfocurl_easy_initcurl_easy_performcurl_easy_resetcurl_easy_setoptcurl_multi_add_handlecurl_multi_initcurl_multi_performcurl_multi_remove_handlecurl_multi_setopt
curl /libcurl /API /Examples /xmlstream.c

xmlstream.c

Related:
All functions
File a bug
Symbols
View in git
View raw
 ### ##  MemoryStruct { *memory;  size_t size;};  ParserStruct { ok;  size_t tags;  size_t depth; MemoryStruct characters;}; ( *userData, XML_Char *name, XML_Char **atts){ ParserStruct *state = ( ParserStruct *) userData;  state->tags++;  state->depth++;   ()name;  ()atts;   free(state->characters.memory);  state->characters.memory = NULL;  state->characters.size = 0;} ( *userData, XML_Char *s, len){ ParserStruct *state = ( ParserStruct *) userData; MemoryStruct *mem = &state->characters;  *ptr = realloc(mem->memory, mem->size + ()len + 1);(!ptr) {    fprintf(stderr,);    state->ok = 0;;  }   mem->memory = ptr;  memcpy(&(mem->memory[mem->size]), s, len);  mem->size += ()len;  mem->memory[mem->size] = 0;} ( *userData, XML_Char *name){ ParserStruct *state = ( ParserStruct *) userData;  state->depth--;   printf(, state->depth, state->characters.size, name);}  size_t( *contents, size_t length, size_t nmemb, *userp){  XML_Parser parser = (XML_Parser) userp;  size_t real_size = length * nmemb; ParserStruct *state = ( ParserStruct *) XML_GetUserData(parser); (state->ok && XML_Parse(parser, contents, ()real_size, 0) == 0) { XML_Error error_code = XML_GetErrorCode(parser);    fprintf(stderr,,            real_size, error_code, XML_ErrorString(error_code));    state->ok = 0;  }  real_size;} (){  CURL *curl_handle;  CURLcode res;  XML_Parser parser; ParserStruct state;   memset(&state, 0,( ParserStruct));  state.ok = 1;   parser = XML_ParserCreateNS(NULL,);  XML_SetUserData(parser, &state);  XML_SetElementHandler(parser, startElement, endElement);  XML_SetCharacterDataHandler(parser, characterDataHandler); curl_global_init(CURL_GLOBAL_DEFAULT);  curl_handle =curl_easy_init();curl_easy_setopt(curl_handle,CURLOPT_URL,);curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, parseStreamCallback);curl_easy_setopt(curl_handle,CURLOPT_WRITEDATA, ( *)parser);   printf();   res =curl_easy_perform(curl_handle);(res != CURLE_OK) {    fprintf(stderr,,curl_easy_strerror(res));  }(state.ok) {(XML_Parse(parser, NULL, 0, 1) == 0) { XML_Error error_code = XML_GetErrorCode(parser);      fprintf(stderr,,              error_code, XML_ErrorString(error_code));    } {      printf();      printf(, state.tags);    }  }   free(state.characters.memory);  XML_ParserFree(parser);curl_easy_cleanup(curl_handle);curl_global_cleanup();  0;}

Notice

This source code example issimplified and ignores returncodes and error checks to a large extent. We do this to highlight the libcurlfunction calls and related options and reduce unrelated code.

A real-world application will of course properly check every return value andexit correctly at the first serious error.


[8]ページ先頭

©2009-2025 Movatter.jp