lr_xml_get_values

XML Functions (lr_xml)

Retrieves values of XML elements found by a query.

int lr_xml_get_values( <List of specifications> [, <List of optional specifications> ] [, LAST]);
List of specifications For the following list of required specifications, use the following string format:"Specification=value"
XML: the XML Input String to query
ValueParam: the name of the output parameter which stores the result of the query. If it does not exist, it is created.
Query: the XML Query or Fast Query on the input string XML. You can specify elements or attributes.
List of optional specifications

For the following list of optional specifications, use the following string format:"Specification=value"

SelectAll: If "yes", all elements matching the query will be processed. If "no", only the first match will be processed. Default is "no". See Multiple Query Matching
NotFound: See Continue on Error

LAST A marker which indicates the end of the List of optional specifications

The lr_xml_get_values function queries the XML input string XML for values matching the Query criteria.

Return Values

See Return Values

Parameterization

See Parameterization

Example 1

The following example uses lr_xml_get_values to search for the name of an employee.

First, a simple XML string is stored in parameter XML_Input_Param. Then, lr_xml_get_values is invoked with the XPath query string "/employee/name". This query is then processed on the XML_Input_Param parameter string. The result of the query is stored in the OutputParam parameter. The value of OutputParam is 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;
}

Example: 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;
}

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

For additional examples, see Examples: common actions.