XactCommerce Xact Objects
Home
News
XactCommerce
Typical Applications
Custom Development
Private Backend
XactScript Language
Performance
Deployment
Partners
Portfolio
About Us
leXml Language < Writing HTML as XML

XML is structurally related to HTML which makes the transition from HTML to XML very easy. XML is much stricter in syntax however, which means that you cannot get away with some of the things that you can in HTML. All tags must have a closing tag (there is a shorthand for empty tags), and XML enforces a tag hierarchy in which there must be a single root tag (usually <html> and </html>). XML also requires that all attributes of tags be enclosed in quotation marks and is case sensitive. The good side of all this is that XML more or less forces you to write perfect HTML, which means that your pages will be viewable on a wider range of browsers.

Here is an example of a simple HTML document and it's counterpart in XML. We have at the moment left out the XML header since we'll talk about that later (it's pretty simple):

    <html>
    <head>
    <title>This is a sample HTML document</title>
    </head>
    <body bgcolor=#ffffff text=#000000>
    <center><p>
    <font face="verdana,arial,helvetica" size=2>
    This is a sample HTML document<br>
    </center></p>
    </body>
    </html>

As you can see that was a very simple HTML document and was pretty well-formed. In HTML you can get away with doing things like leaving out the closing </font> since it's the end of the document. It also doesn't matter in what order you close tags. XML isn't so permissive...

    <html>
    <head>
    <title>This is a sample HTML document</title>
    </head>
    <body bgcolor="#ffffff" text="#000000">
    <center><p>
    <font face="verdana,arial,helvetica" size="2">
    This is a sample HTML document<br/>
    </font>
    </p></center>
    </body>
    </html>

We only had to do a few things. First of all, we had to enclose all attributes in quotes. Secondly, all tags have to have a closing tag. For the <br> tag which has no closing tag in HTML, we still must close it in XML. A tag with an empty tag body like this can be abbreviated with an ending slash. (e.g. instead of <br></br> we use <br/>) Note that the LeXml parser will just output <br> when it outputs HTML from this. LeXml knows which tags don't need closing tags in HTML output. The final change that was required was that tags must be closed in the order they are opened. the <p> tag had to be closed before the <center> tag.

You might notice that most if not all of these changes with the exception of having to close standalone tags are considered to be good HTML coding practice.

The advantages of using XML are several. First of all XML's stricter syntax makes it much quicker for the machine to properly parse XML as a markup language. (HTML's sloppiness-tolerance is one of the things that makes web page renderers so obscenely complicated.) LeXml actually parses through the "inactive" portions of the document as well as it's custom embedded tags. This allows the possibility of doing special things with HTML tags such as outputing special versions of some tags or constructs for some browsers without the page author having to think about this. The second advantage is XML's customizability. XML can inherit and encapsulate other markup definitions, opening up wide ranges of possibility for future integration of other document definitions into web-based applications.

But the above XML code block isn't quite complete. It still needs the XML header and the document type definition. These are quite simple and can be the same for every document. Here is the above code block as a fully complete valid LeXml page:

    <?xml version="1.0"?>

    <!DOCTYPE LeXml SYSTEM "lexml://lexml.dtd">

    <html>
    <head>
    <title>This is a sample HTML document</title>
    </head>
    <body bgcolor="#ffffff" text="#000000">
    <center><p>
    <font face="verdana,arial,helvetica" size="2">
    This is a sample HTML document<br/>
    </font>
    </p></center>
    </body>
    </html>

The LeXml document type definition then includes the HTML4-transitional definition from the W3C which defines all the HTML tags as XML tags, so all you have to include is lexml.dtd. (The URL "lexml://lexml.dtd" is defined in the XML entity resolver configuration section to point to the lexml.dtd file on the system.)

LeXml has it's own tags defined in it's document type definition as well as including the W3C HTML4 definition. All of LeXml's own tags begin with an underscore (_) character. They are <_site>, <_load>, <_call>, <_if>, <_else>, <_endif>, <_include>, <_set>, and <_print> (as well as a few minor ones). These are defined in the LeXml Embeddable Tags section of this documentation.