XML - interaction of DOS-programs and MS Office
Now in operation is a plenty of the program systems (PS) developed for DOS environment. These PS, in most cases, have sufficient functionality, however “design” opportunities of them far lag behind a level set by modern hardware-software means (laser and jet printers, components MS Office).
In some of such PS there is a built-in system of a printing of reports in a RTF-format, suitable for processing in MS Word. Similar RTF-systems have a number of lacks: it is difficult to use various versions of Word, not always successes to take advantage of all opportunities of modern graphic appearance (colors and fonts, a graphic logotype of firm on the form of the document) etc. The printing of such RTF-documents, as a rule, should be made on the same computer on which documents are generated, that, first, slows down speed of work of the operator of system, second, makes practically impossible a printing of such documents of DOS-versions of programs.
For overcoming the specified lacks other way of representation of documents instead of a RTF-format - set of a template of the document prepared in used version MS Word, and programs of generation of the document is offered on the basis of a template and given program system.
The template contains all necessary elements of graphic and text presentation of the document (standard text fragments, blank of tables, graphic elements etc.). Opportunities of appearance are limited only to opportunities of used version MS Word. The information from the program will be worn out in the named fields (bookmarks).
The program of generation of the document on the developed template represents the script in language VBScript. At execution the script causes established in system MS Word with use of the mechanism of an OLE-server, forms the new document on the basis of a template and fills in his(its) fields the information brought PS in a text file in a XML-format. An XML-format is chosen by virtue of the universality (it is possible to store the structured data of various types) and simplicity of use (a field of a template of the document and XML-tags can have identical names, it is not required code conversions of the data if PS do not support the necessary coding). For execution of such script are required component MS Windows Scripting Host (WSH) and COM-object msxml, free delivered with MS Internet Explorer 4 and is higher, and included in MS Windows 98/2000.
The circuit of interaction of program components is given in figure.
Modes of work can vary depending on specific targets. So, at start of the script on the same computer on which client PS functions, the operator is released from necessity to expect loading and unloading MS Word, manually to start a printung of the generated documents: the script is carried out as a separate task of Windows, MS Word on the screen is not showed up, and at once prints the generated documents. However, such variant of operation needs a computer working under MS Windows and having necessary capacity for simultaneous start of client PS and MS Word.
For maintenance of high efficiency of formatting and a printing of documents (for example when some operators PS form invoices and print them for delivery to clients) program components participating in process can be allocated on different computers: DOS-or Windows- clients PS function in a usual mode, and the script and MS Word can be started on the separate computer having on a network access to folders, in which clients PS write down target XML-files with the data. Start of these scripts can be organized with use of the program-monitor which traces the events connected to change of files, and starts necessary handlers such events (in this case the file of the script).
Experiments show, that such configuration allows a computer with average characteristics (processor Celeron/333, the RAM of 64 Mbytes) under management Windows 2000 with established MS Word 2000/XP to print the one-page documents formed on 3…4 workplaces of PS, through 40…60 sec after formation of a XML-file with the data. Documents contain text and tabulared parts with necessary font registration and a graphic logotype.
The files of an example necessary for formatting of such documents, contain in archive Xml2off.zip:
InvSale.xml – a file with the data of three accounts on the sale
InvSale.wsc – file XML-scriptlet containing the Vbscript-description of COM-object “DKMS.InvSale.Scriptlet”, carrying out call MS Word and filling of fields of the document by the information.
MakeFromXML.vbs – the script accepting as parameters a name of a xml-file with the data and a name of the working folder (subdirectory DOT which contains a template of the invoice Invoice.dot.)
Invoice.dot – template MS Word
inv000002.doc – result of work of script MakeFromXML.vbs
readme.txt – the instruction on installation and start of an example.
Files InvSale.xml, InvSale.wsc and MakeFromXML.vbs contain the comments, allowing to execute necessary updatings these files.
Konstantin M. Dyakov
PC Magazine N5/2001