Skip to main content

LOADXML

[attributename := ] LOADXML( xmlstring | symbol [, branch ])

attributenameOptional. The action name, which turns the action into an attribute definition, therefore not executed until the attributename is used as an action.
xmlstringA string expression containing the XML text to process inline (no carriage returns or line feeds).
symbolThe template symbol containing the XML text to process (typically loaded by #EXPORT or #EXPORTXML).
branchA user-defined string naming the XML text, allowing #FOR to operate.

LOADXML opens an active XML scope for Template language statements or symbols to act on. LOADXML must be the first line of code to function correctly.

LOADXML is also used in "drilldown" MACRO code.

Example:

LOADXML('<section><item type="count"><set>person</set></item></section>')
//this macro receives in-line XML as its parameter
//and demonstrates the code for multiple row drilldown
EXPORT id(xmlRow) :=   MACRO
STRING myxmlText := xmlRow;
LOADXML(myxmlText);
#DECLARE(OutStr)
#SET(OutStr, '' )
#FOR(row)
  #APPEND(OutStr,
          'OUTPUT(FETCH(Files.People,Files.PeopleIDX(id='
     + %'id'% + '),RIGHT.RecPos));\n' )
  #APPEND(OutStr,
     'ds' + %'id'%
     + ' := FETCH(Files.Property,Files.PropertyIDX(personid= '
     + %'id'% + '),RIGHT.RecPos);\n' )
  #APPEND(OutStr,
     'OUTPUT(ds' + %'id'%
     + ',{countTaxdata := COUNT(Taxrecs), ds'
     + %'id'% + '});\n' )
  #APPEND(OutStr,
     'OUTPUT(FETCH(Files.Vehicle,Files.VehicleIDX(personid= '
         + %'id'% + '),RIGHT.RecPos));\n' )
#END
%OutStr%
ENDMACRO;
    
//this is an example of code for a drilldown (1 per row)
EXPORT CountTaxdata(xmlRow) := MACRO
LOADXML(xmlRow);
OUTPUT(FETCH(Files.TaxData,
   Files.TaxdataIDX(propertyid=%propertyid%),
   RIGHT.RecPos));
ENDMACRO;

//This example uses #EXPORT to generate the XML

NamesRecord := RECORD
  STRING10 first;
  STRING20 last;
END;
r := RECORD
  UNSIGNED4 dg_parentid;
  STRING10  dg_firstname;
  STRING    dg_lastname;
  UNSIGNED1 dg_prange;
  IFBLOCK(SELF.dg_prange % 2 = 0)
    STRING20 extrafield;
  END;
  NamesRecord namerec;
  DATASET(NamesRecord) childNames;
END;

ds := DATASET('~RTTEST::OUT::ds', r, thor);
   
//Walk a record and do some processing on it.
#DECLARE(out)
#EXPORT(out, r);
LOADXML(%'out'%, 'FileStruct');
   
#FOR (FileStruct)
 #FOR (Field)
  #IF (%'{@isEnd}'% <> '')
OUTPUT('END');
  #ELSE
OUTPUT(%'{@type}'%
   #IF (%'{@size}'% <> '-15' AND
   %'{@isRecord}'%='' AND
   %'{@isDataset}'%='')
+ %'{@size}'%
   #END
+ ' ' + %'{@label}'% + ';');
  #END
 #END
#END
OUTPUT('Done');

See Also: Templates, #EXPORT, #EXPORTXML