What is Miva Script
By Ed Bradburn
Information Officer, NISS
This introduction introduces the Miva scripting language (http://www.miva.com). Although unlike many scripting languages Miva is not open source (or free), it is nevertheless one of the more exciting tag-based languages, capable of producing powerful dynamic content for your website.This tutorial guides you through the features of Miva so you can see for yourself whether it might suit your web development needs.
A. What is miva script?
Miva is an XML-compliant scripting language which pre-parses Miva script files and returns HTML to the browser from this source file. In so doing, it can produce ordinary HTML, DHTML, Javascript, or Java configuration text, and is thus a very useful tool for handling most (if not all) of the common CGI taks required by today's dynamic web content. Although not as fast as CGI scripts written in C, or as powerful as those written in Perl, Miva scripts do have the advantage of being easy to code, simple to debug, and, since they are tag-based, familiar to many semi-technical authors used to writing Javascript, DHTML or simpel HTML, and who class themselves as 'web developers' than 'CGI programmers'.
Developed now by Miva Corporation (http://www.miva.com), it comes in many flavours for most platforms, is a very small (c. 700K) executable, and is simple to install, most setups requiring about 15-30 minutes from unzipping to running a test script.
B. What can it do?
Miva is very strong in the areas for which it was developed and much weaker in those that it was not. This makes it less of an 'all-rounder' like other scripting languages, but for the features it offers, it is hard to beat in terms of both development and maintenance of the systems it can set up. The areas Miva provides most utility in are as follows:
- database support. Miva provides access to two sorts of database structure: ODBC (Windows platforms only) and X-Base .DBF files (any platform). It will also support Oracle in the next release (realistically expect this first quarter 2000). The .DBF format is a fast robust format, and although may be considered outdated in some respects, is perfect for users who merely require fast and convenient access to to non-relational database structures. The author has used .DBF files up to 500MB in size with no problems whatsoever, and indexing, searching and filtering operations are all acceptably fast given the built-in restrictions of the X-Base format.
- handling FORM structures. Miva is especially good at handling the familiar FORMs, and makes the creation of on-line quizzes, feedback, customer orders, guestbooks and even file upload very easy indeed.
- HTML templates and beyond. Miva is brilliant for creating HTML templates to which are then added customer headers/footers and which can be generated in conventional HTML, using frame, or using Javascript to pop-up windows or move to different browser windows. Since all the HTML is pre-parsed by Miva, special effects such as stylesheets, browser (or even text) language, colour, and so forth, can all be conditionally included. Cookies are also handled automatically, and can be set or reset as required.
- Miva uses the POP and SMTP protocols to receive and send mail
- e-commerce. Miva supports a standalone web application called Miva Merchant, also from Miva Corp., which simplifies all facilities provision for web-based commerce, a hot topic at the moment (and likely to continue to be).
- lastly, security and compatibility. Since the work is all XML-compliant, there is no issue with browsers not interpreting Miva. Additionally, since it is server-side, there is also much less risk of tampering with the running of the script and its results.
C. What can't it do?
Although Miva is being continously developed, and thus any or all of these may eventually no longer apply, there are some caveats to anyone considering using it currently for web development:
- it is proprietary. Using Miva will 'tie' you in to Miva products, and if you are more used to using open source tools, and free software, then Miva is not for you. Additionally, the requirement of paying for Miva will obviously restrict the number of devlopers wishing to provide their time for tutorials, free scripts, etc.
- it can be thought of as 'inelegant'. For hard-core programmers, the notion of mixing code with data may be thought of as messy, and aven though Miva can support separate HTML files which are conditionally brought in from scripts containing only code, it is designed to be mixed-in with HTML from the start. Perl programmers shouldn't have too much of a problem with this, althogh Miva scripts are, compared to Perl, one long 'heredocument'.
- database support is not terribly powerful. Knowing Miva's limits with databases, one must be realistic if the required web development is for a large shopping service or library search. Miva databases *can* do very powerful functions (e.g. one of the author's sites searches 2 million records in well under 10 seconds) but more thinking ahead is required than might be with a more powerful tool which is designed specifically for, say, library search engines. It is also not the choice if SQL is your requirement, although Oracle support next year may fix that.
- speed and power are slightly compromised in favour of learning, development and maintenance curves. If your requirement is blazing speed or powerful data crunching, Miva is not the tool for the job, although it must be said that it can still work perfecctly happily with CGI tools that *are*. The author frequently uses 'workhorse' Perl scripts alongside Miva to provide the processing power (e.g. on arrays and file management) whilst Miva gets on with managing the user interface side of the web application.
D. How it works
Simplicity is the key to Miva's power:
- A Miva script is called from the browser and is sent to the Miva CGI executable by the web server.
- The executable parses the script commands and incorporated HTML statements (conditionally or otherwise), and passes the results back to the browser as a standard HTML document.
- The browser interprets the HTML, which may include server-side includes, Javascript, Java configuration text and standard HTML of any flavour, and displays the result to the user.
E. Miva Script Example
<MVCOMMENT>This is not passed to the browser</MVCOMMENT>
<!-- this is passed to the browser as normal -->
<MVASSIGN NAME="var4" VALUE="<PRE>">
<HTML>
<HEAD>
<TITLE>A Miva Script program demo</TITLE>
</HEAD>
<BODY>
<H2>A simple program to demonstrate Miva</H2>
<MVASSIGN NAME="var1" VALUE="5">
<MVASSIGN NAME="var2" VALUE="8">
<MVASSIGN NAME="var3" VALUE="<P CLASS=\"hello\">Hello
there!</P>">
<MVIF EXPR="{5 GT 3}">
<P><B>Simple displaying of variables: &[var2]</P>
<P><B>Simple addition: <MVEVAL EXPR="{var1 +
var2}">.</B></P>
&[var3]
&[var4]
This is not interpreted as HTML, but shown 'as is':
&[var3]
</PRE>
<MVELSE>
<P>This will never occur with that condition!</P>
</MVIF>
</BODY>
</HTML>
F. Example Analysis
This short script demonstrates several things about Miva:
- it is executed linearly, as you would expect. Note that the all Mivascript is parsed for syntax and structural errors before being run. Like other programs, errors that cannot be discovered by Miva before the program is run (e.g. a file missing or a database index not present) will not prevent the program from running;
- Miva can be freely interspersed with HTML tags;
- evaluation requires a dedicated tag syntax (EVAL), but there is another method for simply displaying the contents of a variable(the &[] construction (the macro construction)
- more on both of these later);
- Miva variables can contain HTML tags (together with tag elements, with the appropriate escape letter '\'), and can be displayed and/or evaluated to produce HTML which is then interpreted by the browser. The last part of the script above demonstrates how this works as expected when HTML formatting is temporarily disabled
- comments can be either 'script-level' (using MVCOMMENT) or conventionally given as HTML comments (
<!-- comment -->
).
- lastly, as with HTML, tags can be open or closed, e.g. the IF loop uses a close to indicate the end of the structure, whilst ASSIGNs do not require a closing tag.
The next page of this introduction will discuss variables in more depth, and introduce Miva's best feature - databases.