lr_xml_get_values实践

Examples: lr_xml_get_values

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


 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值