introducing o:XML

Martin Klang <[email protected]> Fri, 25 Jun 2004 16:15:00 +0100
Newsgroups gmane.text.xml.o-xml
Message-ID <[email protected]>
Hi all,

I've been working on an article called 'Introducing o:XML' that I'm 
hoping will be published on xml.com.
Attached is a draft copy, if you have the time and inclination pls read 
and comment back -

best regards,

/m

_______________________________________________
o-xml mailing list
o-xml-zRfLyl9bSvv/[email protected]
http://lists.pingdynasty.com/mailman/listinfo/o-xml
introducing.html (text/html, 13.7 KB)
<html xmlns:ns="http://www.o-xml.org/lang/">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Introducing o:XML</title>
<style>
FORM {margin-bottom: 0px; margin-top: 0px;}
INPUT {margin-bottom: 0px; margin-top: 0px;}
H1 {font-family: Arial, Helvetica, sans-serif; font-weight: bold; font-size: 17px;}
H2 {font-family: Arial, Helvetica, sans-serif; font-weight: bold; font-size: 17px;}
H3 {font-family: Arial, Helvetica, sans-serif; font-weight: bold; font-size: 15px;}
H4 {font-family: Arial, Helvetica, sans-serif; font-weight: bold; font-size: 13px; margin-bottom: 0px; margin-top: 0px; padding-top: 0px; padding-bottom: 0px; padding-right: 0px; padding-left: 0px;}
CODE {color: #003366; font-size: 10pt; font-family: Courier New,Courier;}
PRE {font-family: Courier New,Courier; font-size: 10pt; color: #003366; margin-left: 9pt;}
	</style>
</head>
<body>
  <h2>Introducing o:XML</h2>

  
    <h3>Introduction</h3>
  <p>o:XML recently celebrated its second anniversary, and has since its birth spawned a dozen separate projects. Still it has remained a low profile endeavour, little publicised and not widely known to the growing, and growingly diverse, XML developer community.</p>
  <p>So what is o:XML? Well it's a dynamically typed, general purpose object-oriented programming language. It's got threads, exception handling, regular expressions, namespaces and all the other things you can expect from a modern language. Oh, and it's expressed entirely in XML. It's maybe a bit like Python crossed with XSLT. Let's look at an example.</p>
 
   <p><b>Example 1: Hello World</b></p>
<pre><code>
<b>&lt;o:program&gt;</b>
  <b>&lt;o:type name="HelloWorld"&gt;</b>
    <b>&lt;o:function name="hello"&gt;</b>
      <b>&lt;o:do&gt;</b>
	<b>&lt;o:return select="'Hello World'"/&gt;</b>
      <b>&lt;/o:do&gt;</b>
    <b>&lt;/o:function&gt;</b>
  <b>&lt;/o:type&gt;</b>
  <b>&lt;o:set instance="HelloWorld()"/&gt;</b>
  <b>&lt;o:eval select="$instance.hello()"/&gt;</b>
<b>&lt;/o:program&gt;</b>
</code></pre>
  
<p>XML being XML, the result is a verbose language which many will find difficult to read and hard to write. It doesn't look like a 'real' programming language like C or Java. And let's face it, there are already too many programming languages in the world. So why o:XML? Before addressing that question I will offer a short overview of the language itself.</p>

  


  <h3>Language Overview</h3>
<p>Running an o:XML program produces XML output - XML contained within the program is simply copied to the output. With this knowledge we can rewrite 'Hello World' as follows:</p>


<p><b>Example 2: Hello Again</b></p>
<pre><code><b>&lt;o:do&gt;</b>Hello World!<b>&lt;/o:do&gt;</b></code></pre>

<p>Since o:XML is object-oriented, everything is an object and every object has a type. The basic types are String, Element, Document etc, representing types of XML nodes. There are also collection types, and an evolving set of core libraries. Users can of course create their own types and functions.</p>
<p>o:XML has an expression language very similar to XPath. The main difference is that o:Path allows functions to be invoked on nodes and nodesets, just like with objects in Java or C++. Since in o:XML nodes <i>are</i> objects, o:Path can be used not only to find and select nodes, but also to modify and change their state.</p>

  <p><b>Example 3: o:Path Expression</b></p>
  <pre><code>//a[@href.contains('cnn.com')].remove()</code></pre>
  <p>removes all 'a' elements with 'href' attributes containing the text "cnn.com"</p>

<p>Any valid XML document is a valid o:XML program. Furthermore, o:XML can be embedded anywhere in an XML document. Embedded use of o:XML means that dynamic content can be included in a document without breaking XML validity. o:XML exists in its own namespace, and respects document integrity.</p>
<p>Imagine for example that you would like to produce an RSS 2.0 feed detailing all files in a given directory. We construct a simple program, using the o:Lib <i>io</i> module to access the filesystem.</p>

  <p><b>Example 4: RSS Feed</b></p>
<pre><code>
&lt;rss version="2.0"&gt;
  &lt;channel&gt;
    &lt;title&gt;File System Contents&lt;/title&gt;
    &lt;link&gt;http://www.o-xml.org/&lt;/link&gt;
    &lt;description&gt;An o:XML example.&lt;/description&gt;
    <b>&lt;o:import href="lib/io.oml"/&gt;</b>                           1
    <b>&lt;o:set dir="io:File('.')"/&gt;</b>                             2
    <b>&lt;o:for-each name="file" select="$dir.list()"&gt;</b>           3
      &lt;item&gt;
        &lt;title&gt;<b>&lt;o:eval select="$file.name()"/&gt;</b>&lt;/title&gt;      4
        &lt;link&gt;file://<b>&lt;o:eval select="$file.path()"/&gt;</b>&lt;/link&gt;
      &lt;/item&gt;
    <b>&lt;/o:for-each&gt;</b>
  &lt;/channel&gt;
&lt;/rss&gt;
</code></pre>
<p>1 load the io module</p>
<p>2 set the variable <i>dir</i> by creating a File that represents <i>'.'</i>, the current directory</p>
<p>3 iterate over all files in the directory, assigning each one to the variable <i>file</i></p>
<p>4 get the file name and insert the value into the <i>title</i> element</p>

<p>The above example represents a complete o:XML program. If you run this program from the command line, it will produce an RSS output with one <i>item</i> element for each file in the current directory</p>


<p>When an o:XML program is deployed in a Servlet engine, it will take its parameters from an HTTP request. So our commandline scripts work without modification as REST-ful web services. They can equally well be called from within an Ant build script, with Ant providing the parameter values dynamically.</p>

<p>The next example produces an SVG chart of the number of words in a DocBook document, broken down by section.</p>

<p><b>Example 5: DocBook Word Count</b></p>
<pre><code>
<b>&lt;o:program&gt;</b>
  <b>&lt;o:param name="file"/&gt;</b>
  <b>&lt;o:import href="lib/io/File.oml"/&gt;</b>
  &lt;svg:svg&gt;
    <b>&lt;o:for-each select="io:File($file).parse()//section"&gt;</b>
      <b>&lt;o:set x="count(preceding::section) * 30 + 20"/&gt;</b>
      <b>&lt;o:set height="count(.//text().match('\w')) * 2"/&gt;</b>
      &lt;svg:rect width="10"&gt;
	<b>&lt;o:attribute name="x" select="$x"/&gt;</b>
	<b>&lt;o:attribute name="y" select="200 - $height"/&gt;</b>
	<b>&lt;o:attribute name="height" select="$height"/&gt;</b>
      &lt;/svg:rect&gt;
      &lt;svg:text style="writing-mode:tb"&gt;
	<b>&lt;o:attribute name="x" select="$x + 5"/&gt;</b>
	<b>&lt;o:attribute name="y" select="205"/&gt;</b>
	<b>&lt;o:eval select="title/text()"/&gt;</b>
      &lt;/svg:text&gt;
    <b>&lt;/o:for-each&gt;</b>
  &lt;/svg:svg&gt;
<b>&lt;/o:program&gt;</b>
</code></pre>




  <h3>X is for eXtensible</h3>
<p>As expected, o:XML provides the same capabilities as most other modern languages. Being XML, it also allows for processing and extensions, which doesn't come naturally to conventional programming languages. What this means in practice is firstly that we can harness the power of tools and technology developed for XML. Secondly, our code integrates seamlessly with practically every other XML vocabulary.</p>
<p>I illustrated earlier how o:XML programs can be inlined in RSS documents and used to generate SVG output. We will now take a brief look at how the source code itself can be extended.</p>

<p>The following is an example taken from the o:Lib implementation of an internet <i>Message</i>. It includes two separate extensions: Documentation and Unit Tests. The automated build produces cross-referenced type documentation, unit tests and test results. This is achieved with standard XML processing tools such as XSLT.</p>

<p><b>Example 6: Extensions in net:Message type definition</b></p>
<pre><code>
<b>&lt;o:type name="net:Message"&gt;</b>
  &lt;doc:p&gt;Represents, loosely, an RFC822 Internet Message&lt;/doc:p&gt;
  <b>&lt;o:function name="header"&gt;</b>
    <b>&lt;o:param name="name"/&gt;</b>
    &lt;doc:p&gt;Get a message header&lt;/doc:p&gt;
    <b>&lt;o:do&gt;</b>
      <b>&lt;o:return select="$headers.get($name)"/&gt;</b>
    <b>&lt;/o:do&gt;</b>
    &lt;ut:test&gt;
      &lt;ut:input ref="msg1"/&gt;
      &lt;ut:definition&gt;
	<b>&lt;o:set msg="net:Message($input.string())"/&gt;</b>
	<b>&lt;o:return select="$msg.header('Host')"/&gt;</b>
      &lt;/ut:definition&gt;
      &lt;ut:result&gt;localhost:8090&lt;/ut:result&gt;
    &lt;/ut:test&gt;
  <b>&lt;/o:function&gt;</b>
<b>&lt;/o:type&gt;</b>
</code></pre>



<p>There is no limit to the type or nature of extensions that may be incorporated into o:XML source code, as long as the data can be expressed in XML. Currently available extensions vary from documentation and embedded tests to declarations that alters the behaviour of an application, such as <i>Design By Contract</i> assertions and <i>Aspect Oriented Software Development</i> definitions. The possibilities are almost endless: An integrated development lifecycle starting with requirements, through definition and UML modelling, to development, test plans and deployment, could be centered around a common XML information repository.</p>



  <h3>Why o:XML?</h3>
<p>And so we return to the question: why o:XML? My preferred answer would be: using the same format for code as we use for data allows us to think slightly differently about the code. The application is not only a runtime executable, magically incantated by the source code - it is structured data, information, a document. With XML, the source code is made transparent, it can be processed in the same way, with the same tools that we use for other structured information - writing o:XML programs that generate or instrument other programs is remarkably easy. The XML code format allows for orthogonal extensions, integrates with development methodologies and is a natural test-bed for abstract languages, meta- and reflective programming.</p>

<p>So o:XML puts us at the forefront of computer science. However, this answer neglects the fact that o:XML is also a practical language, designed to solve practical problems. For many types of applications it already provides faster, easier, better solutions than any other technology. If you are writing code that processes or produces XML, chances are you could benefit from using o:XML.</p>



  <h3>Project Status</h3>
  <p>The key component of o:XML is the Java based compiler and interpretor, ObjectBox, which recently went into production release with version 1.0. ObjectBox allows o:XML programs to run standalone, from an Ant build file or within a Servlet engine such as Tomcat. It also allows for integration with existing Java applications using either BSF or its own native API. ObjectBox offers a full, stable implementation of o:XML.</p>
  <p>The core language is supported by extensions and library code. The o:XML 'standard library' is o:Lib, which in its latest release includes file, stream, network and XSLT functionality.</p>
  <p>In addition to library code there are also several language extensions available. Java extensions allow Java classes to be used seamlessly in o:XML programs. The popular db extensions handle database connection pooling and transactions, while providing a uniquely simple, powerful RDBMS to XML mapping mechanism.</p>



  <h3>Looking to the Future</h3>
  <p>o:XML has come a long way in two years, but has many more miles to go! There are vast areas still to be explored.</p>
  <p>Work has already started on the next generation o:XML compiler, ObjectBox 2. It will be centered around a portable, native language transformation engine. The goal is to produce efficient code for a number of targets, including Java Bytecode and C, using o:XML tools throughout.</p>
  <p>There has also been growing interest in defining an abstract XML programming language, based on a generic superset of o:XML. This is similar in focus to the <a href="http://www.tel.fer.hr/users/mtopol/jezix/">Jezix project</a>.</p>
  <p>There are efforts underway to produce a minimal-footprint engine for embedded and portable devices such as PDA's and mobile phones. This work will either branch off the current ObjectBox project or be incorporated into ObjectBox 2.</p>
  <p>A great deal of work has taken place on lifecycle and methodology integration. o:XML lends itself to processing and code generation like no other language, and using XML tools means that every step in the process is transparent. There's more information about workflow integration <a href="http://o-xml.org/docs/tools.html">on the o:XML website</a>.</p>



  <h3>Projects</h3>
  <p>o:XML has evolved into a whole family of projects. Below is a non-exhaustive list.</p>
<table>
  <p><b>Open-source o:XML Projects</b></p>
  <tr>
    <td><i>ObjectBox</i></td>
    <td><p>o:XML compiler and interpretor in Java</p></td>
  </tr>
  <tr>
    <td><i>hatatap</i></td>
    <td><p>HTTP test script language and tools</p></td>
  </tr>
  <tr>
    <td><i>vendue</i></td>
    <td><p>online auctioning software written in o:XML with db extensions</p></td>
  </tr>
  <tr>
    <td><i>o:Lib</i></td>
    <td><p>o:XML core libraries</p></td>
  </tr>
  <tr>
    <td><i>sandbox</i></td>
    <td><p>open development and social software platform</p></td>
  </tr>
  <tr>
    <td><i>db extensions</i></td>
    <td><p>powerful yet simple relational database connectivity</p></td>
  </tr>
  <tr>
    <td><i>flo:XML</i></td>
    <td><p>code transformations and end-to-end lifecycle integration</p></td>
  </tr>
  <tr>
    <td><i>o:XML meta</i></td>
    <td><p>o:XML implementation of Aspect Oriented Software Development, reflection and meta-programming</p></td>
  </tr>
</table>



<h3>Links</h3>
<table>
<tr>
<td>-</td>
<td><a href="http://www.o-xml.org/">o:XML website</a></td>
</tr>
<tr>
<td>-</td>
<td><a href="http://hatatap.pingdynasty.com/">hatatap project site</a></td>
</tr>
<tr>
<td>-</td>
<td><a href="http://vendue.pingdynasty.com/">vendue project site</a></td>
</tr>
</table>




</body>
</html>