After hitting a http server I get response in XML format. I am using libcurl for this purpose. I was thinking to use some xml parser, but when I see their API they all take a xml file but I have the data in a char *.
Is there any XML parser available which takes char * as input
My code is in C on Linux.
I am a newbie to XML domain :)
开发者_开发技巧#include <curl/curl.h>
size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp)
{
printf ("\n punith\n");
printf ("\n size %d\n",size);
printf ("\n no. of mem %d\n",nmemb);
printf ("\n%s\n",(char *)userp);
printf ("%s",(char *)buffer);
}
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.1.188:80/un.xml");
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
My output will be
<RNQueryRsp>
<RefID>ABCD999001</RefID>
<PN>919012345678</PN>
<Result>1</Result>
<RN>1414</RN>
<DNO>100</DNO>
<NRHN>101</NRHN>
<LSA>XY</LSA>
</RNQueryRsp>
libxml2's xmlCtxtReadMemory()
maybe?
cf. http://xmlsoft.org/html/libxml-parser.html#xmlCtxtReadMemory
Have a look at libxml2.
First of all, what is the environment you are working? Linux, windows?
You are not mentioning the apis you saw, and I find it strange. May be what you saw was only to load the xml file to be read?
Check this from GNOME http://xmlsoft.org/
精彩评论