Page 1 of 1

XML to HTML?

Posted: Tue May 11, 2004 4:03 pm
by Karbon
I'm writing a report module for this billing program and it needs to output formatted reports. I'm thinking about using XML to gather the data and pass it off to something that will make pretty HTML for me. The problem is that I've never used XML and don't know if XML to HTML is a viable option..

If anyone has experience with writing XML based reporters please drop me a note and lets discuss it! :-)

Posted: Tue May 11, 2004 5:29 pm
by Flype
i have experimented some good things
i'll prepare you a small example :wink:

Posted: Tue May 11, 2004 5:47 pm
by blueznl
you could leave it in xml, as most (modern) browsers do support xml these days, why translate it to html or xhtml?

Posted: Tue May 11, 2004 6:45 pm
by Flype
here is an example of how to parse an xml file
and then display it in html format

this includes the xmlparser.dll and pb includes to use it
and you should copy xmlparser.dll to purebasic/compilers folder

http://www.serveurperso.com/~flype/Pure ... L_HTML.zip

XML to HTML

Posted: Wed May 12, 2004 10:01 am
by ppjm99
Apparently XSLT is an XML transformation language whose sole purpose is to translate XML into onther formats like HTML. I have been investigating this stuff lately and would love to see some support for XML and SVG in purebasic in the future as they are both open and patent free standards I believe.

Posted: Wed May 12, 2004 10:44 am
by aXend
XML to HTML is very easy, using XSTL and creating a XSL file. See the following code in javascript.

Code: Select all

<html>
<body>
<script language="javascript">
// Load XML 
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("xmlfile.xml")

// Load the XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("xslfile.xsl")

// Transform
document.write(xml.transformNode(xsl))
</script>

</body>
</html>
The XSL code could be something like this

Code: Select all

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="html"/>
<xsl:decimal-format name="european" decimal-separator="," grouping-separator="." />

<xsl:template match="/">
<html>
<style type="text/css">
body {font-family:Arial; font-size:8pt;}
table {font-family:Arial; font-size:8pt;}
#wg {font-size:10pt;}
#pagebreak {page-break-before:always;}
</style>
<body>
element1 <xsl:value-of select="root/element1"/><br/>
<br/><hr/>
<xsl:for-each select="root/element1/subelement">
	<table width="100%" border="0">
	  	<tr>
			<td>subelement</td>
			<td><xsl:value-of select="item1"/></td>
			<td><xsl:value-of select="item2"/></td>
			<td><xsl:value-of select="item3"/></td>
	  	</tr>
	</table>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Hope this helps.

Posted: Wed May 12, 2004 12:32 pm
by Karbon
Awesome stuff guys.. Thanks Flype for the example!

Thanks aXend for the XSTL stuff, I'm going to investigate how I can implement something like that..

Posted: Fri May 14, 2004 7:06 pm
by Karbon
aXend: to better help me understand how this all works (I'm reading, but there is a lot to read!). Could you provide a quickie example of the XML that would make that XSL stylesheet spit something out?

Thanks in advance!

Posted: Fri May 14, 2004 7:41 pm
by Karbon
I think I have a handle on it now.. Just going to find some external (or globally accessible) XSL translation tool and I'm GOLDEN!

[edit].. I would use javascript to render to HTML but I need access to HTML code itself to save (and email, etc).. I don't believe javascript is allowed to write files, so is there any other way to get the HTML code (perhaps from a web gadget or the like?)

Posted: Fri May 14, 2004 7:59 pm
by aXend
I think the easiest way is to start iexplore.exe with the html file like I gave as example. In the html file you link the xmlfile to the xslfile and iexplore.exe renders the output automatically using msxml.exe. You can save the output or print the output, whatever you like.

If you have something else in mind: let me know. Good luck.

Posted: Fri May 14, 2004 8:13 pm
by Karbon
When it saves it saves as the javascript, though, because it is rendered dynamically...