BltInFunc-LoadXML.xml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
  4. <sect1 id="LOADXML">
  5. <title>LOADXML</title>
  6. <para><emphasis>[</emphasis><emphasis>attributename</emphasis> :=<emphasis
  7. role="bold"> ] LOADXML<indexterm>
  8. <primary>LOADXML</primary>
  9. </indexterm><indexterm>
  10. <primary>LOADXML function</primary>
  11. </indexterm>( </emphasis><emphasis> xmlstring | symbol
  12. </emphasis><emphasis role="bold">[</emphasis><emphasis>, branch
  13. </emphasis><emphasis role="bold">])</emphasis></para>
  14. <informaltable colsep="1" frame="all" rowsep="1">
  15. <tgroup cols="2">
  16. <colspec colwidth="83.05pt" />
  17. <colspec />
  18. <tbody>
  19. <row>
  20. <entry><emphasis>attributename</emphasis></entry>
  21. <entry>Optional. The action name, which turns the action into an
  22. attribute definition, therefore not executed until the
  23. <emphasis>attributename</emphasis> is used as an action.</entry>
  24. </row>
  25. <row>
  26. <entry><emphasis>xmlstring</emphasis></entry>
  27. <entry>A string expression containing the XML text to process inline
  28. (no carriage returns or line feeds).</entry>
  29. </row>
  30. <row>
  31. <entry><emphasis>symbol</emphasis></entry>
  32. <entry>The template symbol containing the XML text to process
  33. (typically loaded by #EXPORT or #EXPORTXML).</entry>
  34. </row>
  35. <row>
  36. <entry><emphasis>branch</emphasis></entry>
  37. <entry>A user-defined string naming the XML text, allowing #FOR to
  38. operate.</entry>
  39. </row>
  40. </tbody>
  41. </tgroup>
  42. </informaltable>
  43. <para><emphasis role="bold">LOADXML </emphasis>opens an active XML scope for
  44. Template language statements or symbols to act on. LOADXML must be the first
  45. line of code to function correctly.</para>
  46. <para>LOADXML is also used in "drilldown" MACRO code.</para>
  47. <para>Example:</para>
  48. <programlisting>LOADXML('&lt;section&gt;&lt;item type="count"&gt;&lt;set&gt;person&lt;/set&gt;&lt;/item&gt;&lt;/section&gt;')
  49. //this macro receives in-line XML as its parameter
  50. //and demonstrates the code for multiple row drilldown
  51. EXPORT id(xmlRow) := MACRO
  52. STRING myxmlText := xmlRow;
  53. LOADXML(myxmlText);
  54. #DECLARE(OutStr)
  55. #SET(OutStr, '' )
  56. #FOR(row)
  57. #APPEND(OutStr,
  58. 'OUTPUT(FETCH(Files.People,Files.PeopleIDX(id='
  59. + %'id'% + '),RIGHT.RecPos));\n' )
  60. #APPEND(OutStr,
  61. 'ds' + %'id'%
  62. + ' := FETCH(Files.Property,Files.PropertyIDX(personid= '
  63. + %'id'% + '),RIGHT.RecPos);\n' )
  64. #APPEND(OutStr,
  65. 'OUTPUT(ds' + %'id'%
  66. + ',{countTaxdata := COUNT(Taxrecs), ds'
  67. + %'id'% + '});\n' )
  68. #APPEND(OutStr,
  69. 'OUTPUT(FETCH(Files.Vehicle,Files.VehicleIDX(personid= '
  70. + %'id'% + '),RIGHT.RecPos));\n' )
  71. #END
  72. %OutStr%
  73. ENDMACRO;
  74. //this is an example of code for a drilldown (1 per row)
  75. EXPORT CountTaxdata(xmlRow) := MACRO
  76. LOADXML(xmlRow);
  77. OUTPUT(FETCH(Files.TaxData,
  78. Files.TaxdataIDX(propertyid=%propertyid%),
  79. RIGHT.RecPos));
  80. ENDMACRO;
  81. //This example uses #EXPORT to generate the XML
  82. NamesRecord := RECORD
  83. STRING10 first;
  84. STRING20 last;
  85. END;
  86. r := RECORD
  87. UNSIGNED4 dg_parentid;
  88. STRING10 dg_firstname;
  89. STRING dg_lastname;
  90. UNSIGNED1 dg_prange;
  91. IFBLOCK(SELF.dg_prange % 2 = 0)
  92. STRING20 extrafield;
  93. END;
  94. NamesRecord namerec;
  95. DATASET(NamesRecord) childNames;
  96. END;
  97. ds := DATASET('~RTTEST::OUT::ds', r, thor);
  98. //Walk a record and do some processing on it.
  99. #DECLARE(out)
  100. #EXPORT(out, r);
  101. LOADXML(%'out'%, 'FileStruct');
  102. #FOR (FileStruct)
  103. #FOR (Field)
  104. #IF (%'{@isEnd}'% &lt;&gt; '')
  105. OUTPUT('END');
  106. #ELSE
  107. OUTPUT(%'{@type}'%
  108. #IF (%'{@size}'% &lt;&gt; '-15' AND
  109. %'{@isRecord}'%='' AND
  110. %'{@isDataset}'%='')
  111. + %'{@size}'%
  112. #END
  113. + ' ' + %'{@label}'% + ';');
  114. #END
  115. #END
  116. #END
  117. OUTPUT('Done');
  118. </programlisting>
  119. <para>See Also: <link linkend="Templates">Templates</link>, <link
  120. linkend="_EXPORT">#EXPORT</link>, <link
  121. linkend="_EXPORTXML">#EXPORTXML</link></para>
  122. </sect1>