Share this page

# lr_xml_set_values

XML Functions (lr_xml)

Sets the values of XML elements found by a query.

    int lr_xml_set_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 ResultParam: The output parameter containing the XML data after setting the new value. If the parameter does not exist, it is created. Query: the XML Query on the input string XML. You can specify elements or attributes. Choose one of the following: Value: the string value to set as the XML element or: ValueParam: the parameter name containing the value to set as the XML element
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_set_values function queries the XML input string XML for values matching the Query criteria and sets either Value or ValueParam as the value of the elements matched by the query.

The XML input string can be a literal string containing XML data. For example:

"XML=<employee>John Smith</employee>

Alternatively, the XML string can be a parameter containing the XML data. For example:

"XML={EmployeeNameParam}"

You can pass the input value required as a string ("Value=string"), or as a parameter which contains the string ("ValueParam={Param}").

If there is more than one value to be replaced, then use ValueParam. Save the values in a series of parameters with the names:

Param_1, Param_2, Param_3, ...

where Param is the value "ValueParam=Param". lr_xml_set_values sets each successive match of the Query to the value of the next parameter in the series.

When parameters with the names ValueParam or ResultParam already exist, their value is overwritten. ResultParam is returned using the source document encoding. The output preserves the XML Character Encoding of the original document, independent of the input encoding. The input encoding uses the client's local encoding.

For information and examples about Query see XML Query.

## Return Values

See Return Values

## Parameterization

See Parameterization

## Example

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 Examples: common actions.

Copy code

    #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
        lr_save_string("1111", "ExtensionParam_1");
        lr_save_string("2222", "ExtensionParam_2");
        lr_xml_set_values("XML={XML_Input_Param}",
            "ResultParam=NewXmlParam",
            "ValueParam=ExtensionParam",
            "SelectAll=yes",
            "Query=//extension",
            LAST );
        NumOfValues= lr_xml_get_values("XML={NewXmlParam}",
            "ValueParam=OutputParam",
            "Query=//extension",
            "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);
            lr_output_message(lr_eval_string(buf));
        }
        return 0;
    }

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

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: