loadrunner中的代码如下:
long fp;
int total = 0;
int readbufsize = 0;
int count = 0;
int i = 0;
int NumOfReadbuf_1 = 0;
int NumOfReadbuf_2 = 0;
int NumOfReadbuf_3 = 0;
int NumOfReadbuf_4 = 0;
char *readbuf;
char *file = "D:\\test.xml";
//读取XML文件
if ( (fp = fopen(file,"r")) == NULL)
{
lr_message("open logfile Failed!\n");
return -1;
}
//申请 readbuf
readbuf = (char*) calloc(50,sizeof(char));
if (readbuf == NULL)
{
lr_message("Insufficient memory available");
return -1;
}
//循环读取文件
while(!feof(fp))
{
// 扩展缓冲区
if( readbufsize - total <= 10 )
{
readbufsize += 50;
readbuf = (char*) realloc(readbuf,readbufsize);
}
count = fread(readbuf + total,sizeof(char),10,fp);
total += count;
}
//修改readbuf内存值
readbuf = (char*) realloc(readbuf,readbufsize+1);
*(readbuf+total) = '\0';
//保存参数
lr_save_string(readbuf,"readbuf_param");
//读取记录
NumOfReadbuf_1 = lr_xml_get_values("XML={readbuf_param}",
"ValueParam=id",
"Query=/employee/id",
"SelectAll=yes",
LAST);
NumOfReadbuf_2 = lr_xml_get_values("XML={readbuf_param}",
"ValueParam=name",
"Query=/employee/name",
LAST);
NumOfReadbuf_3 = lr_xml_get_values("XML={readbuf_param}",
"ValueParam=add",
"Query=/employee/add",
LAST);
NumOfReadbuf_4 = lr_xml_get_values("XML={readbuf_param}","ValueParam=age","Query=/employee/age","SelectAll=yes",LAST); //输出结果 lr_log_message("%s",lr_eval_string("{id_1}")); lr_log_message("%s",lr_eval_string("{name_1}")); lr_log_message("%s",lr_eval_string("{add_1}")); lr_log_message("%s",lr_eval_string("{age_1}"));