LotusScript Library to easily create XML files
Category lotusscript xml
I've just uploaded a LotusScript file to my downloads that is a LotusScript class to easily create and export XML files from lotusscript. This library is perfect for creating tight xml code when size or custom "schemas" are required versus using the ?readviewentries command from a view. I use it all the time in conjunction with an XSLT style sheet and the free Altova XML kit to apply a XSL Stylesheet to generate HTML reports.
The class is not completed yet, as I haven't implemented a way to read and then manipulate the XML yet, but you can completely create and export with it. Enjoy...
I've just uploaded a LotusScript file to my downloads that is a LotusScript class to easily create and export XML files from lotusscript. This library is perfect for creating tight xml code when size or custom "schemas" are required versus using the ?readviewentries command from a view. I use it all the time in conjunction with an XSLT style sheet and the free Altova XML kit to apply a XSL Stylesheet to generate HTML reports.
The class is not completed yet, as I haven't implemented a way to read and then manipulate the XML yet, but you can completely create and export with it. Enjoy...
Here's some sample code on how to use the
library.
There are two ways to utilize the class. The first is to tell it to read and export a view, using the column name as the tag:
The second way is to parse out your own structure and add nodes to the tree yourself, like this (also includes sample usage of Altova XML's COM object to apply an XSL Stylesheet and generate an HTML report):
Using this method, and Google Charts, here is an example of a report you could output using this method (hightly redacted of course)
There are two ways to utilize the class. The first is to tell it to read and export a view, using the column name as the tag:
Sub Initialize
On Error Goto Handler
Dim MyTestXML As New XMLFile("TestTag")
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim view As NotesView
Set View = db.GetView("AIR")
MyTestXML.ViewImportOptions = XMLFILE_VIEWIMPORT_SMRY
Call MyTestXML.ImportView(View)
Call MyTestXML.WriteFile("C:\Test.xml", False)
Delete MyTestXML
Exit Sub
Handler:
Print "An Error occured. Error#" + Str$(Err) + " on line " + Str$(Erl) + " :: " + Error$(Err)
Exit Sub
End Sub
On Error Goto Handler
Dim MyTestXML As New XMLFile("TestTag")
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim view As NotesView
Set View = db.GetView("AIR")
MyTestXML.ViewImportOptions = XMLFILE_VIEWIMPORT_SMRY
Call MyTestXML.ImportView(View)
Call MyTestXML.WriteFile("C:\Test.xml", False)
Delete MyTestXML
Exit Sub
Handler:
Print "An Error occured. Error#" + Str$(Err) + " on line " + Str$(Erl) + " :: " + Error$(Err)
Exit Sub
End Sub
The second way is to parse out your own structure and add nodes to the tree yourself, like this (also includes sample usage of Altova XML's COM object to apply an XSL Stylesheet and generate an HTML report):
Sub Click(Source As Button)
Dim myxml As New xmlfile("CheckDetails")
Dim ctag As xmltag
Dim dtag As xmltag
Dim ftag As xmltag
' ... do your processing here ... probably a loop, etc
Set dtag=myxml.documenttag.appendchild("Check")
Call dtag.addattribute("CheckNumber", Cstr(nve.ColumnValues(0)))
Set ftag=dtag.appendchild("LineItem")
Set ctag=ftag.appendchild("Details")
ctag.InnerText="Total"
Set ctag = ftag.AppendChild("Amount")
ctag.InnerText= Str$(total)
' ... finish your processing here....
Call myxml.writefile("c:\test.xml", False)
' Example calling AltovaXML's COM object to apply a style sheet to the export XML to output an HTML report....
Dim xlsfilename As String
xlsfilename=Outxsl ' Outxsl is a function that writes the XSL to a file and returns the file name....
Dim xlator As Variant
Set xlator = CreateObject("AltovaXML.Application")
Dim OutputURL As String
On Error Goto AltovaError
xlator.XSLT2.XSLFileName = xlsfilename
xlator.XSLT2.InputXMLFileName = "C:\test.xml"
Dim x As String
Call xlator.XSLT2.Execute("C:\test.htm") ' Output the file to HTML
Call ws.URLOpen("file://C|/test.htm")
CleanHouse:
Kill XMLFileName
Exit Sub
AltovaError:
Print "AltovaXML(): An error occoured. Error #" + Str$(Err) + " on line " + Str$(Erl) + " :: " + Error$(Err)
Exit Sub
End Sub
Dim myxml As New xmlfile("CheckDetails")
Dim ctag As xmltag
Dim dtag As xmltag
Dim ftag As xmltag
' ... do your processing here ... probably a loop, etc
Set dtag=myxml.documenttag.appendchild("Check")
Call dtag.addattribute("CheckNumber", Cstr(nve.ColumnValues(0)))
Set ftag=dtag.appendchild("LineItem")
Set ctag=ftag.appendchild("Details")
ctag.InnerText="Total"
Set ctag = ftag.AppendChild("Amount")
ctag.InnerText= Str$(total)
' ... finish your processing here....
Call myxml.writefile("c:\test.xml", False)
' Example calling AltovaXML's COM object to apply a style sheet to the export XML to output an HTML report....
Dim xlsfilename As String
xlsfilename=Outxsl ' Outxsl is a function that writes the XSL to a file and returns the file name....
Dim xlator As Variant
Set xlator = CreateObject("AltovaXML.Application")
Dim OutputURL As String
On Error Goto AltovaError
xlator.XSLT2.XSLFileName = xlsfilename
xlator.XSLT2.InputXMLFileName = "C:\test.xml"
Dim x As String
Call xlator.XSLT2.Execute("C:\test.htm") ' Output the file to HTML
Call ws.URLOpen("file://C|/test.htm")
CleanHouse:
Kill XMLFileName
Exit Sub
AltovaError:
Print "AltovaXML(): An error occoured. Error #" + Str$(Err) + " on line " + Str$(Erl) + " :: " + Error$(Err)
Exit Sub
End Sub
Using this method, and Google Charts, here is an example of a report you could output using this method (hightly redacted of course)














- 
Comments
Posted by Tracy At 10:25:15 PM On 12/11/2009 | - Website - |
I've made changes:
1) in constructor
replacesrc(0) = "&"
replacedes(0) = "&"
replacesrc(1) = """"
replacedes(1) = """
replacesrc(2) = "<"
replacedes(2) = "<"
replacesrc(3) = ">"
replacedes(3) = ">"
replacesrc(4) = "'"
replacedes(4) = "'"
2) in property "InnerText"
Me.myInnerText = Replace( InnerText, replacesrc, replacedes )
3) in property "AddAttribute"
Me.myAttributes(AttName) = Replace( AttValue, replacesrc, replacedes )
Posted by Andrew S Golembiovsky At 06:41:59 AM On 08/04/2009 | - Website - |