人的差别在于业余时间,而一个人的命运决定于晚上8点到10点之间。 北京安全测试精英QQ群:164265622 北京白盒测试精英QQ群:164265999 北京性能测试精英QQ群:164266156 北京自动化测试精英群:212723528 北京软件测试精英QQ群:86920845

Examples: lr_xml_get_values

上一篇 / 下一篇  2011-12-07 19:28:18 / 个人分类:性能测试

Example 1

The following example useslr_xml_get_valuesto search for the name of an employee.

First, a simple XML string is stored in parameterXML_Input_Param. Then,lr_xml_get_valuesis invoked with the XPath query string "/employee/name". This query is then processed on theXML_Input_Paramparameter string. The result of the query is stored in theOutputParamparameter. The value ofOutputParamis evaluated using lr_eval_string.

#include "as_web.h"
char *xml_input=
     "<employee>"
          "<name>John Smith</name>"
          "<cubicle>227</cubicle>"
     "</employee>";

Action() {

     lr_save_string(xml_input, "XML_Input_Param"); // Save input as parameter

     lr_xml_get_values("XML={XML_Input_Param}",
          "ValueParam=OutputParam",
          "Query=/employee/name",
          LAST);

     lr_output_message(lr_eval_string("Query result = {OutputParam}"));

     return 0;
}

Output:
Action.c(13): "lr_xml_get_values" was successful, 1 match processed
Action.c(18): Query result = John Smith

Example 2

The following example is similar to Example 1 except that multiple values are retrieved. The query retrieves all telephone extensions from the XML input string,xml_input.

#include "as_web.h"

char * xml_input =
"<acme_org>"
     " <accounts_dept>"
          "<employee>"
               " <name>John Smith</name>"
               "<cubicle>227</cubicle>"
               "<extension>2145</extension>"
          "</employee>"
     "</accounts_dept>"
     "<engineering_dept>"
          "<employee>"
               "<name>Sue Jones</name>"
               "<extension>2375</extension>"
          "</employee>"
     "</engineering_dept>"
"</acme_org>";

Action() {

     int i, NumOfValues;
     char buf[64];

     lr_save_string(xml_input, "XML_Input_Param"); // Save input as parameter

     NumOfValues=lr_xml_get_values("XML={XML_Input_Param}",
          "ValueParam=OutputParam",
          "Query=/acme_org/*/employee/extension",
          "SelectAll=yes", LAST);

     for ( i = 0; i < NumOfValues; i++) { /* Print multiple values of OutputParam */

          sprintf (buf, "Retrieved value %d : {OutputParam_%d}", i+1, i+1);
          lr_output_message(lr_eval_string(buf));
     }

     return 0;
}

Output:
Action.c(34): Retrieved value 1 : 2145
Action.c(34): Retrieved value 2 : 2375


TAG:

 

评分:0

我来说两句

Open Toolbar