Share this page

# lr_xml_extract

XML Functions (lr_xml)

Extracts XML fragments from an XML string.

    int lr_xml_extract( <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 XMLFragmentParam: the name of the output parameter containing the extracted XML string fragment Query: the XML Query or Fast Query on the input string XML.
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 ResolveNameSpaces: If "no", then XMLFragmentParam will contain the extracted string as it appears in the XML input. If "yes", then XMLFragmentParam will includefull resolution of any namespace prefixes (e.g., "a:body") in the XML input string. The Default is "no". NotFound: See Continue on Error OutputFormat: One of `utf-8` or `locale`. Default is `locale`.
LAST | A marker which indicates the end of the List of optional specifications.

The lr_xml_extract function queries the XML input string XML and extracts the fragments of the XML tree which match the Query criteria. The output parameter XMLFragmentParam contains the extracted fragments.

## Return Values

See Return Values

## Parameterization

See Parameterization

## Example

The following example uses lr_xml_extract to retrieve the employees in the engineering department from the XML string xml_input. lr_xml_extract extracts the entire string fragment that makes up the tag /acme_org/engineering_dept/employee.

The resulting fragment is stored in the XMLFragmentParam parameter Result, which is sent to the output at the end of the test.

For more examples of the use of lr_xml_extract, 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 level=\"manager\">"
                   "<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_xml_extract("XML={XML_Input_Param}",
              "XMLFragmentParam=Result",
              "Query=/acme_org/engineering_dept/employee", LAST );

         lr_output_message(lr_eval_string("Extracted: {Result}"));

         return 0;
    }

Example: Output:
Action.c(31): Extracted: <employee level="manager"><name>Sue Jones</name><extension>2375</extension></employee>

## Example 2

Copy code

    In the following example, lr_xml_extract extracts an attribute and its value from the <i>employee</i> element.
    lr_xml_extract( "Xml={XML_Input_Param}",
        "Query=/acme_org/engineering_dept/employee/@level",
        "XMLFragmentParam=Result",
        LAST
        );
        lr_output_message(lr_eval_string("***** {Result} *****"));

Example: Output:
Action1.c(117): "lr_xml_extract" was successful, 1 match processed
Action1.c(122): ***** level="manager" *****

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: