Whether you want to deliver XML to another processing application or to a client browser, such as Microsoft Internet Explorer Version 5, you can use the XML block structure to deliver XML content.
The XML block works in the same manner as the HTML block; it is an entry or exit point for the macro. Within the block you can enter XML tags directly, reference variables, and make function calls. When you make a function call within an XML block, Net.Data knows to present the results using XML tags instead of HTML.
So that you can customize the generated XML document to your needs, the XML block does not generate the prolog tags. Enter the prolog information particular to your enterprise and include a stylesheet of your choice. Included with Net.Data are three XSL stylesheets that you can use. These stylesheets contain transforms for all of the XML and HTML elements generated by Net.Data (the generated HTML elements conform to the emerging XHTML standard). The stylesheets are examples, however, and you are encouraged to expand on these or create your own.
Figure 20. A macro containing an XML report block
%DEFINE DATABASE = "SAMPLE" %FUNCTION(DTW_SQL) NewManager(){ select * from staff where job = 'Mgr' and years <= 5 %} %XML(report) { <?xml version="1.0" ?> <?xml-stylesheet type="text/xsl" href="ndTable.xsl" ?> <XMLBlock> <h1>List of New Managers</h1> @NewManager() </XMLBlock> %} |
Net.Data generates the information in the XML block using a small set of elements, as shown in the following document description:
<!--------------------------------------------------------> <!-- The root element used in all XML output generated --> <!-- by Net.Data is the XMLBlock element. --> <!--------------------------------------------------------> <!ELEMENT XMLBlock (RowSet|ShowSQL|Message)*> <!ATTLIST XMLBlock name CDATA #IMPLIED> <!--------------------------------------------------------> <!-- The default presentation format for tables uses --> <!-- the RowSet, Row, and Column elements. --> <!--------------------------------------------------------> <!ELEMENT RowSet (Row)*> <!ATTLIST RowSet name CDATA #IMPLIED> <!ELEMENT Row (Column)*> <!ATTLIST Row name CDATA #IMPLIED number CDATA #IMPLIED> <!ELEMENT Column (#PCDATA)> <!--------------------------------------------------------> <!-- SQL statements resulting from setting the SHOWSQL --> <!-- variable are presented with the ShowSQL element. --> <!--------------------------------------------------------> <!ELEMENT ShowSQL (#PCDATA)> <!--------------------------------------------------------> <!-- SQL statements resulting from setting the SHOWSQL --> <!-- variable are presented with the ShowSQL element. --> <!--------------------------------------------------------> <!ELEMENT Message (#PCDATA)>
The elements are defined as follows:
Example:
If the following function were called in an XML block, its associated RowSets would be displayed as shown.
%FUNCTION(DTW_SQL) call_sp() { CALL stored_proc %} %XML(report){ ... <RowSet name="call_sp" number="1">...</RowSet> <RowSet name="call_sp" number="2">...</RowSet> ... %}
Using the elements above, Net.Data would generate the following output from the macro listed in Figure 20.
Content-type: text/xml <?xml version="1.0" ?> <?xml-stylesheet type="text/xsl" href="ndTable.xsl" ?> <XMLBlock> <h1>List of New Managers</h1> <RowSet name="NewManager"> <Row number="1"> <Column name="ID">30</Column> <Column name="NAME">Marenghi</Column> <Column name="DEPT">38</Column> <Column name="JOB">Mgr</Column> <Column name="YEARS">5</Column> <Column name="SALARY">17506.75</Column> <Column name="COMM"></Column> </Row> <Row number="2"> <Column name="ID">240</Column> <Column name="NAME">Daniels</Column> <Column name="DEPT">10</Column> <Column name="JOB">Mgr</Column> <Column name="YEARS">5</Column> <Column name="SALARY">19260.25</Column> <Column name="COMM"></Column> </Row> </RowSet> </XMLBlock>
Figure 21 and Figure 22 show how the above data would appear in a browser using two of the stylesheets provided with Net.Data: ndTable.xsl and ndRecord.xsl.
Figure 21. XML displayed using the ndTable.xsl stylesheet
![]() |
Figure 22. XML displayed using the ndRecord.xsl stylesheet
![]() |