lr.xmlExtract

Extracts XML fragments from an XML string.

ExampleXML 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
xmlThe XML Input String to query.
xmlFragmentParamThe name of the output parameter containing the extracted XML string fragment.
queryThe XML Query on the input string XML. You can specify elements or attributes.
fastQueryThe Fast Query on the input string XML. You can specify elements or attributes.
selectAllIf "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
resolveNameSpacesIf "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".
notFoundSee Continuing on Error
outputFormatOne 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;
}