Share this page

# lr.xmlExtract

Extracts XML fragments from an XML string.

JavaScript XML Functions (lr.xml)

## Syntax

    lr.xmlExtract( {object} );

## JavaScript Object

    {
       xml:"<string>",
       xmlFragmentParam:"<string>",
       query:"<string>", | fastQuery:"<string>",
       selectAll:"<string>",
       resolveNameSpaces:"<string>",
       notFound:"<string>",
       outputFormat:"<string>"
    }

Property Name | Description
--- | ---
xml | The XML Input String to query.
xmlFragmentParam | The name of the output parameter containing the extracted XML string fragment.
query | The XML Query on the input string XML. You can specify elements or attributes.
fastQuery | The Fast Query on the input string XML. You can specify elements or attributes.
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 Continuing on Error
outputFormat | One of `utf-8` or `locale`. Default is `locale`.

The lr.xmlExtract 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

All XML functions return the number of matches successfully found or zero on failure.

## Parameterization

Input parameters to XML functions with the following names can be parameterized:

- XML

- Query

- Value

- XmlFragment

## Example

    function Action(){
       var xmlInput =
           "<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>";

        lr.saveString(xmlInput, "XML_Input_Param"); // Save input as parameter

        lr.xmlExtract({xml:'{XML_Input_Param}',
              xmlFragmentParam : 'Result',
              query: '/acme_org/engineering_dept/employee'});

        lr.outputMessage(lr.evalString("Extracted: {Result}"));

    return 0;
    }

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: