XmlPL By Example: Hello World!, Web Page

The classic hello world program does not really exercise many of the features which make XmlPL special. It is an XML processor after all. So here is hello world, web page.

Steps

  1. Create Bare Web Page
  2. Add Hello World! String
  3. Output The String
  4. Compile & Run
  5. View The Results

1. Create Bare Web Page

node[] main() {
  <http>
    <head>
    </head>
    <body>
    </body>
  </http>
}

First create a blank Web page by outputting some XML data from main. Remember that the node[] return type indicates that main will output a stream of XML nodes.

2. Add Hello World! String

node[] main() {
  string helloString = "Hello World!";

  <http>
    <head>
    </head>
    <body>
    </body>
  </http>
}

This step creates a variable, helloString and initializes it to the value "Hello World!".

3. Output The String

node[] main() {
  string helloString = "Hello World!";

  <http>
    <head>
      <title>helloString;</title>
    </head>
    <body>
      <h1>helloString;</h1>
    </body>
  </http>
}

Output both page title and first header. Hello world, Web page is complete.

4. Compile & Run

The following shell script will compile and execute the program.

#!/bin/sh

xmlplcc hello_web.xpl
./hello_web >index.html

5. View The Results

The previous step should have produced a file index.html with the following contents.

<?xml version="1.0" encoding="UTF-8"?>
<http><head><title>Hello World!</title></head><body><h1>Hello World!</h1></body></http>

Notice there are no unnecessary spaces.

Below, you can see the resulting Web page.