Infintuary.org

XML to HTML converter

Converting XML to HTML doesn't sound very impressive and is in fact rather simple but can still be useful, if you want to display XML code (or even HTML code) on a website.

The XML to HTML converter converts XML code like this:
<?xml version='1.0'?><sample><entry attrib='xyz'>This is an entry</entry></sample>
into HTML code like this:
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>XML as HTML</title> <style type="text/css"> *{ margin: 0px; padding: 0px;} html,body{background: #FFFFFF; } code{font-family: Courier New, sans-serif; font-size: 12px; color: #000000; } #op{color: #0000FF; } #att{color: #FF0000; } #qut{color: #000000; } #val{color: #008000;font-weight:bold; } #com{color: #808080;font-style:italic; } #txt{color: #000000;font-weight:bold; } #cdata{color: #800080; } #proc{color: #0000FF; } #doc{color: #0000FF; } #tag{color: #800000; } </style> </head> <body> <code> <span id="op"><?</span><span id="proc">xml</span><span id="txt"/><span id="att">version</span><span id="op">=</span><span id="qut">"</span><span id="val">1.0</span><span id="qut">"</span><span id="op">?></span><br/><span id="txt"/><span id="op"><</span><span id="tag">sample</span><span id="op">></span><br/> <span id="txt">&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="op"><</span><span id="tag">entry</span><span id="txt"/><span id="att">attrib</span><span id="op">=</span><span id="qut">"</span><span id="val">xyz</span><span id="qut">"</span><span id="op">></span><span id="txt">This is an entry</span><span id="op"></</span><span id="tag">entry</span><span id="op">></span><br/> <span id="op"></</span><span id="tag">sample</span><span id="op">></span><br/> </code> </body> </html>
which is displayed by a web browser like this:
<?xml version="1.0" ?> <sample>     <entry attrib="xyz">This is an entry</entry> </sample>
The colors of the various XML elements can either be set in the source code of the converter or in the generated HTML code.

The XML to HTML converter is basically a Delphi class that can be compiled into your application, but I also made a very simple test tool to demonstrate the functionality of the Delphi class. I tested the code with Delphi 2007 only, but it shouldn't be difficult to adapt it to other versions of Delphi.

Download XML to HTML converter (304 KB)

The zip file contains the full source code of the XML to HTML converter as well as a test tool (for Windows).

The XML to HTML converter is freeware and can be used for any purpose.
By downloading the XML to HTML converter you agree to the terms of use.

If you like the XML to HTML converter and find it useful, feel free to donate.