I'm trying to load an XML file from an URL using pugixml parser. The problem is that if you want to load a file from URL you have to load it from memory which it's very confusing for me. This is what I've tried and it doesn't work:
char* source = "http://some_url.xml";
int size = 256;
char* buffer = new char[size];
memcpy(buffer, source, size);
pugi::xml_document doc;
doc.load_buffer_inplace(buffer, size);
...
delete[] buffer;
Here is their documentation: https://pugixml.org/docs/manual.html#loading.memory
Can someone who is more familiar with that stuff please give me an example of how to do it.
If anyone is interested.. this is how I solved it:
const char* f = "new_file.xml";
if (curl){
const char* c_url = "some_url";
FILE* ofile = fopen(f, "wb");
if (!ofile) { fprintf(stderr, "Failed to open file: %s\n", strerror(errno)); }
if (ofile){
curl_easy_setopt(curl, CURLOPT_URL, c_url);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, ofile);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeData);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_perform(curl);
fclose(ofile);
}
}
pugi::xml_document doc;
doc.load_file(f);
Thanks for all the help guys!