XML to HTML?

Everything else that doesn't fall into one of the other PB categories.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

XML to HTML?

Post 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! :-)
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

i have experimented some good things
i'll prepare you a small example :wink:
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

you could leave it in xml, as most (modern) browsers do support xml these days, why translate it to html or xhtml?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post 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
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
ppjm99
User
User
Posts: 23
Joined: Mon Jun 02, 2003 7:39 pm
Location: Canada

XML to HTML

Post 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.
aXend
Enthusiast
Enthusiast
Posts: 103
Joined: Tue Oct 07, 2003 1:21 pm
Location: Netherlands

Post 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.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post 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..
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post 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!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post 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?)
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
aXend
Enthusiast
Enthusiast
Posts: 103
Joined: Tue Oct 07, 2003 1:21 pm
Location: Netherlands

Post 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.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

When it saves it saves as the javascript, though, because it is rendered dynamically...
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Post Reply