Thursday, July 19, 2007

Simple LotusScript-library to fetch html/transform xml

I rewrote some of the code so that there only will be created one object per task. In my first version, I created an object per URL-call. In this version, only one object is created per task.

Text-file with code
Put code under '(declarations) in the file, into the declarations part of the scriptlib, and 'Terminate into the terminate part. The functions place themselves when you paste them.

'(declarations)
Dim httpobj As Variant
Dim source As Variant, style As Variant

'Terminate
Set httpobj = Nothing
Set source = Nothing
Set style = Nothing


If you want to get several XML-/XSL-files from the same source, you only need to login once per agent. If you're going to use the same XSL template for each xml-source, you only need to load this the first time.

'..
login = "https://server.com/names.nsf?login&"+_
"username=foo&password=bar"

xmlurl = "https://server.com/db.nsf/first.xml"
xslurl = "https://server.com/db.nsf/first.xsl"

'first call
Print transformXML( login, xmlurl, xslurl )
'..
'second call, same xsl-template
xmlurl = "https://server.com/db.nsf/second.xml"
Print transformXML( "", xmlurl, "" )
'..
'third call, different xsl-template
xmlurl = "https://server.com/db.nsf/view?ReadViewEntries"
xslurl = "https://server.com/db.nsf/view.xsl"
Print transformXML( "", xmlurl, xslurl )
'..

2 comments:

Dwight Wilbanks said...

For the first several years of my lotusscript development career I did know about (or use) static declarations.

Since I discovered them (hidden in plain site) I've faithfully used them in place of globals when the var is only used in one place.

Tommy Valand said...

After looking at this article, I agree that that using static declarations/singletons is the best way of coding this small lib.

I'll have to set of some time to learn this programming pattern.

I have quite a lot I'd like to learn, but I seem to end up mostly wasting my time on other things..