|
基本信息:lr版本:9.5
协议:http/html
Action()
{
#include "as_web.h"
char *xmlt ="";
char *xml_input =
"<acme_org>"
"<employee>John</employee>"
"<cubicle>227</cubicle>"
"<app>227</app>"
"<test>227</test>"
"</acme_org>";
int find_cnt;
//int OutputParam;
lr_save_string(xml_input, "XML_Input_Param");
find_cnt = lr_xml_find("XML={XML_Input_Param}",
"Value=John",
"Query=/acme_org/employee",
LAST );
if (find_cnt >0)
{
lr_xml_insert("XML={XML_Input_Param}", "ResultParam=Result",
"XmlFragment=<extension>2145</extension>",
"Query=/acme_org/employee",
"Position=child", LAST );
lr_output_message(lr_eval_string("String after insertion: {Result}"));
}
lr_save_string("1111", "ExtensionParam_1");
lr_save_string("2222", "ExtensionParam_2");
lr_xml_set_values("XML={XML_Input_Param}",
"Query=//test",
"ResultParam=NewXmlParam",
"ValueParam=ExtensionParam",
"SelectAll=yes",
LAST );
lr_output_message(lr_eval_string("String after insertion: {NewXmlParam}"));
lr_save_string("{NewXmlParam}","xmlt");
lr_xml_get_values("XML={xmlt}",
"Query=//test",
"ValueParam=Result",
"SelectAll=yes",
"NotFound=continue",
LAST);
lr_output_message(lr_eval_string("String after insertion: {Result}"));
lr_output_message(lr_paramarr_idx("Result",1));
return 0;
}
回放信息:
Starting iteration 1.
Starting action Action.
Action.c(32): "lr_xml_find" succeeded, 1 match processed
Action.c(42): "lr_xml_insert" succeeded, 1 match processed
Action.c(50): String after insertion: <acme_org><employee>John<extension>2145</extension></employee><cubicle>227</cubicle><app>227</app><test>227</test></acme_org>
Action.c(56): "lr_xml_set_values" succeeded, 1 match processed
Action.c(67): String after insertion: <acme_org><employee>John</employee><cubicle>227</cubicle><app>227</app><test>1111</test></acme_org>
Action.c(71): Warning: "lr_xml_get_values" did not find any matches
Action.c(82): String after insertion: <acme_org><employee>John<extension>2145</extension></employee><cubicle>227</cubicle><app>227</app><test>227</test></acme_org>
Action.c(83): {Result_1}
Ending action Action.
Ending iteration 1.
疑问:1、为什么传参的时候名字是ExtensionParam、而变量赋值的时候名字是ExtensionParam_1 如果两个处的名字相同替换的内容就自动加上“_1”
2、如果lr的修改xml文件内容的要求就是两处名称不一样,那么当有多个参数传参的时候如何处理。
3、脚本中最后一段代码的目的是想输入test标签修改后的值。但输出的信息还是修改前的值。(此处有可能是我代码写的不对,如果有人事先了请告诉我一下) |
|