Summer 2001
|
INTRODUCTION
XML Extensible Markup Language is the latest web technology to directly affect mainstream business IT. It allows you to separate content the stored data from its processing or presentation.
It does this by storing data values between identifying tags, very much like HTML. But, as you can see from this example:
<PERIODICAL> <TITLE>MV News</TITLE> <ISSUE>1</ISSUE> <YEAR>2001</YEAR> </PERIODICAL>
you can create your own tags! Tags are defined in a Document Type Definition (DTD). The DTD can be stored as a file in its own right and can include, as well as a basic definition, types of data and their relationships to each other. In e-commerce the DTD can be shared amongst all participants and becomes the standard by which their data exchanges are regulated.
The way each element is presented can, additionally, be specified in a style sheet using Extensible Style Language (XSL) or by using a Cascading Style Sheet (CSS) more familiar to HTML practitioners.
As well as being the lynch-pin technology in e-commerce, XML is also likely to become the preferred format for storage of word processing files, spreadsheets and suchlike. Microsoft is already implementing XML (or XML-like) formats for its Office applications and, not surprisingly, Internet Explorer 5.x is XML-enabled.
With the introduction of SVG (Standard Vector Graphics) as an integrated part of XML technology we can now truly save MV data, publish it as XML and present it in any format required. (At the time of writing you need to download a SVG plug-in for IE 4 or 5 and Netscape Navigator. See references at the end of this piece.)
While techniques for MV are developing and associated products become available creating XML documents from any MV data source is quite straightforward using nothing more than the standard MV toolset.
To see how we might generate XML documents from MV databases well start by looking at an XML document, what it is and how it works, and then at how to output the XML using Access. Well then see how one XML document can be used to create output in several styles.
What is an XML document?
XML documents consist of two sections, a Prolog and a Document Element (sometimes called the Root Element). The prolog always contains the XML declaration:
<?xml version=1.0?>
Note that the literal 1.0 can be contained in single or double quotes: 1.0 or 1.0, which can be useful when nesting quoted literals in Access.
The prolog can also contain the Document Type Definition (DTD) and presentation styles.
The Document Element consists of XML elements nested within the Root Element.
Unlike HTML, XML is case sensitive. Start and end tags must be identical, as in:
<CUSTOMER> </CUSTOMER>
The combination
<Customer> </CUSTOMER>
will generate an error.
How is an XML document linked to definition or style files?
A DTD can be included in the XML file, as used in the Table example below, or it can be stored in another file which is referenced in the XML document prolog.
Similarly, presentation style can be included as in-line code or a reference to an external file, as in:
<?xml-stylesheet type=text/css href=SALES_ANALYSIS_LIST.CSS?>
This reference format is used in the following examples.
Format an Access listing with XML tags
You can create a marked-up output file from MV from a DataBASIC program or using the Access processor. Because Access allows you to define a header, creating the XML prolog is straightforward. The body of the XML document, the Document Element, requires the data fields to be marked up with XML tags. These tags can be included in DICT items or BREAK-ON text.
The examples below use a single MV source file called CUSTOMER_FILE (Fig. 1, above).
100011 100012 100014 001 GT Smith 001 Bill Morrison 001 I Patel 002 104.66 002 139.81 002 111.00 003 SON001 003 SONO11]SONO12]SONO13 003 SONO90]SONO95 004 104.66 004 10.22]109.60]19.99 004 55.50]55.50 Fig. 1: Extract from CUSTOMER_FILE |
ORDER_OPEN ORDER_NUMBER ORDER_CLOSE 001 A 001 A 001 A 002 3 002 3 002 3 003 Order open tag 003 Order number 003 Order close tag 004 004 004 005 005 005 006 006 006 007 007 007 008 F;C<ORDER> 008 F;C<NUMBER>;3;:;C</NUMBER>;: 008 F;C</ORDER> 009 L 009 R 009 L 010 7 010 23 010 8 Fig.2: Order number dictionary items |
CUSTOMER_OPEN CUST_NUMBER 001 A 001 A 002 0 002 0 003 Customer open tag 003 Account 004 004 005 005 006 006 007 007 008 F;C<CUSTOMER> 008 F;C<ACCOUNT>;0;:;C</ACCOUNT>;: 009 L 009 L 010 10 010 25 Fig. 3: Customer dictionary items |
SORT CUSTOMER_FILE CUSTOMER_OPEN BREAK-ON CUST_NUMBER </CUSTOMER> CUST_NAME SALES_TOTAL ORDER_OPEN ORDER_NUMBER ORDER_VALUE ORDER_CLOSE HEADING <?xml version=1.0?><SALES> FOOTING </SALES> ID-SUPP COL- HDR-SUPP Fig. 4: Access listing outputting XML document SALES_ANALYSIS.XML |
Creating dictionary items for XML output
When tags need to be synchronised with multivalues, DICT items should reference the MV attribute and output data surrounded by XML tags, as shown by this order number triplet (Fig.2, above).
Where multivalues are nested inside a parent tag, as with order details inside the <CUSTOMER> </CUSTOMER> pair, a DICT item can be used to output the parents opening tag and data while the element can be closed using BREAK-ON text.
For instance:
... CUSTOMER_OPEN BREAK-ON CUST_NUMBER </CUSTOMER> ...
with these DICT items (Fig. 3, above) generates the output:
<CUSTOMER><ACCOUNT>100011</ACCOUNT></CUSTOMER>
<?xml version=1.0?> <SALES> <CUSTOMER> <ACCOUNT>100011</ACCOUNT> <NAME>GT Smith</NAME> <SALES_TOTAL>104.66</SALES_TOTAL> <ORDER> <NUMBER>SON001</NUMBER> <VALUE>104.66</VALUE> </ORDER> </CUSTOMER> <CUSTOMER> <ACCOUNT>100012</ACCOUNT> <NAME>Bill Morrison</NAME> <SALES_TOTAL>139.81</SALES_TOTAL> <ORDER> <NUMBER>SON011</NUMBER> <VALUE>10.22</VALUE> </ORDER> <ORDER> <NUMBER>SON012</NUMBER> <VALUE>109.60</VALUE> </ORDER> <ORDER> <NUMBER>SON013</NUMBER> <VALUE>19.99</VALUE> </ORDER> </CUSTOMER> <CUSTOMER> <ACCOUNT>100014</ACCOUNT> <NAME>I Patel</NAME> <SALES_TOTAL>111.00</SALES_TOTAL> <ORDER> <NUMBER>SON090</NUMBER> <VALUE>55.50</VALUE> </ORDER> <ORDER> <NUMBER>SON095</NUMBER> <VALUE>55.50</VALUE> </ORDER> </CUSTOMER> </SALES> Fig. 5: XML document SALES_ANALYSIS.XML |
Access listing
This outputs the basic marked-up data which is saved as XML document SALES_ANALYSIS.XML:
This should be a columnar listing if it drops to a vertical list, use the Access fill (or r) option or use TERM to widen the output.
DOCUMENTS AND THEIR OUTPUT
Basic marked-up data
Access listing saved to a file named SALES_ANALYSIS.XML (Fig. 5).
Using Internet Explorer 5, opening an XML document which contains no stylesheet results in the XML being checked by IEs XML processor and the display of the document as structured XML. Any errors are reported by IE, a useful testing option!
Simple list
To create a simple list of order details, we can apply the stylesheet SALES_ANALYSIS_LIST.CSS (Fig. 7, right) by including a reference in the XML prolog. The XML file can be opened in IE 5 to display the list of order details.
Note: SALES_ANALYSIS_01.XML (Fig. 6) is a copy of SALES_ANALYSIS.XML with the stylesheet reference shown bold added.
.xml file SALES_ANALYSIS_01.XML <?xml version=1.0?> <! FILE NAME: SALES_ANALYSIS_01.XML > <?xml-stylesheet type=text/css href=SALES_ANALYSIS_LIST.CSS?> <SALES> <CUSTOMER> <ACCOUNT>100011</ACCOUNT> ... Fig. 6: SALES_ANALYSIS_01.XML |
.css stylesheet file SALES_ANALYSIS_LIST.CSS /* FILE NAME: SALES_ANALYSIS_LIST.CSS USED WITH: SALES_ANALYSIS_01.XML */ CUSTOMER {display:block; margin-top:12pt; font-size:12pt; font-family:arial} ACCOUNT {font-weight=bold} NAME {font-weight=bold} SALES_TOTAL {display:block; margin-left:2.5in; font-weight:bold; text-decoration:underline overline} ORDER {display:block} NUMBER {display:inline} VALUE {display:inline} Fig. 7: Stylesheet SALES_ANALYSIS_LIST.CSS |
.xml file SALES_ANALYSIS_02.XML <?xml version=1.0?> <! FILE NAME: SALES_ANALYSIS_01.XML > <?xml-stylesheet type=text/css href=SALES_ANALYSIS_SUMMARY.CSS?> <SALES> <CUSTOMER> <ACCOUNT>100011</ACCOUNT> ... Fig. 8: SALES_ANALYSIS_02.XML |
.css stylesheet file SALES_ANALYSIS_SUMMARY.CSS /* FILE NAME: SALES_ANALYSIS_SUMMARY.CSS USED WITH: SALES_ANALYSIS_02.XML */ CUSTOMER {display:block; margin-top:12pt; font-size:12pt; font-family:arial} ACCOUNT {font-weight=bold} NAME {font-weight=bold} SALES_TOTAL {display:block; margin-left:2.5in} ORDER {display:none} Fig. 9: Stylesheet SALES_ANALYSIS_SUMMARY.CSS |
Summary list
In this summary list the XML prolog references SALES_ANALYSIS_SUMMARY.CSS (Fig. 9) which is similar to the detail list example except that the element ORDER is set to display:none. The order number and order value NUMBER and VALUE - which are children of ORDER, inherit their parents display option, giving a summary list of customers and order totals.
Note: SALES_ANALYSIS_02.XML (Fig. 8) is a copy of SALES_ANALYSIS_01.XML with the stylesheet reference changed as shown in bold.
SALES_ANALYSIS_03.HTM <HTML> <!-- File name: SALES_ANALYSIS_03.htm --> <HEAD> <TITLE>Sales analysis from SALES_ANALYSIS_03.XML</TITLE> </HEAD> <BODY> <XML ID="dsoSales" SRC="SALES_ANALYSIS_03.XML"></XML> <FONT FACE="Arial"> <TABLE DATASRC="#dsoSales" WIDTH=100% BORDER=1 CELLSPACING=5> <THEAD> <TH> <STRONG>SALES ANALYSIS BY CUSTOMER</STRONG> </TH> </THEAD> <TR> <TD> <SPAN DATAFLD="ACCOUNT"></SPAN> </TD> <TD> <SPAN DATAFLD="NAME"></SPAN> </TD> <TD> <TABLE DATASRC="#dsoSales" DATAFLD="ORDER" WIDTH=100% BORDER=2 CELLSPACING=2> <THEAD> <TH> <STRONG>ORDER DETAILS</STRONG> </TH> </THEAD> <TR> <TD> <SPAN DATAFLD="NUMBER"></SPAN> </TD> <TD ALIGN="RIGHT"> <SPAN DATAFLD="VALUE"></SPAN> </TD> </TR> </TABLE> </TD> <TD ALIGN="RIGHT"> <SPAN DATAFLD="SALES_TOTAL"></SPAN> </TD> </TR> </TABLE> </FONT> </BODY> </HTML> Fig. 10: SALES_ANALYSIS_03.HTM |
Table
In this example we see data binding at work: We bind a HTML table to the XML data source and use it to format and display order details.
Note: SALES_ANALYSIS_03.XML (Fig. 11, right) is a copy of SALES_ANALYSIS.XML with the DTD added, as shown emboldened.
In this example we need to embed the XML in HTML. To examine this example, open SALES_ANALYSIS_03.htm using IE5.
SALES_ANALYSIS_03.XML <?xml version=1.0?> <! FILE NAME: SALES_ANALYSIS_03.XML > <! A valid XML document including a document type definition > <!DOCTYPE SALES [ <!ELEMENT SALES (CUSTOMER*)> <!ELEMENT CUSTOMER (ACCOUNT, NAME, SALES_TOTAL, ORDER*)> <!ELEMENT ACCOUNT (#PCDATA)> <!ELEMENT NAME (#PCDATA)> <!ELEMENT SALES_TOTAL (#PCDATA)> <!ELEMENT ORDER (NUMBER, VALUE)> <!ELEMENT NUMBER (#PCDATA)> <!ELEMENT VALUE (#PCDATA)> ] > <SALES> <CUSTOMER> <ACCOUNT>100011</ACCOUNT> ... Fig. 11: SALES_ANALYSIS_03.XML |
Column chart
We can create a column chart using Standard Vector Graphics (SVG), without changing the XML document or the Access listing which generated it. This topic will be covered in the next issue.
NEXT STEPS
Some instances have been hardcoded for clarity (and to save space!)
For instance, links to stylesheets have been hardcoded, not determined conditionally. A useful next step would be to integrate all incarnations of the XML document and its associated stylesheets.
Familiarity with the XML standards will also allow you to write XML parsers necessary to read XML documents and populate MV files with their content.
REFERENCES
Chris has a background in software development that goes back to the late 70s and assembler, Fortran and FORTH. His first brush with Reality came during the mid-80s when he worked for MD CSC, and for the remainder of that decade and into the early 90s he coded RPL, Databasic, SB and later SB+ as a contractor. Increasingly, his work involved MV-to-desktop integration, mostly using TERMiTE and ViaDuct (but he wonders if anyone still remembers the DUMBo dumb terminal emulator for DOS that he wrote in 1989).
In 1992 he joined Lawson Mardon as Systems Manager in York, later becoming Business Analyst on Lawson Mardon's European SAP implementation. Since July 1999 he has been manager of BI Applications for Lawson Mardon UK and Ireland, using Cognos BI products and developing for the web.
Last Updated: 20 Jul 2001