Example: lr_xml_set_values

The following example uses lr_xml_set_values to change the phone extensions of two employee elements in an XML string.

First, a simple XML string is stored in parameter XML_Input_Param. Since we want two values to be matched and substituted, we prepare two new parameters, ExtensionParam_1 and ExtensionParam_2, and set them to two new phone extensions, 1111 and 2222.

lr_xml_set_values is invoked passing "ValueName=ExtensionParam", which picks up the values of ExtensionParam_1 and ExtensionParam_2. The current extensions of the two employees are substituted with the values of these parameters, 1111 and 2222. The value of OutputParam is then evaluated proving that the new phone extensions were indeed substituted.

For more examples of the use of lr_xml_set_values, see Set attribute values in Example Scripts for XML Queries.

#include "as_web.h"
char * xml_input = 
    " <accounts_dept>"
            " <name>John Smith</name>"
            "<name>Sue Jones</name>"
Action() {
    int i, NumOfValues;
    char buf[64];
    lr_save_string(xml_input, "XML_Input_Param"); // Save input as parameter
    lr_save_string("1111", "ExtensionParam_1");
    lr_save_string("2222", "ExtensionParam_2");
        LAST );
    NumOfValues= lr_xml_get_values("XML={NewXmlParam}",
        "SelectAll=yes", LAST );
    for ( i = 0; i < NumOfValues; i++) { /* Print the multiple values of MultiParam */
        sprintf (buf, "Retrieved value %d : {OutputParam_%d}", i+1, i+1);
    return 0;

Example: Output:
Action.c(40): Retrieved value 1 : 1111
Action.c(40): Retrieved value 2 : 2222