Categories





IM me on the bleedyellow.com sametime community - jeremy.hodge@zetaone.com

« My "wrap-up" on xPages, thoughts on the life and/or death of the Notes Client, and an update on YellowBubble.org | Main| Second Vulnerability Discovered in Microsoft DirectShow ActiveX Component, Zero Day Attacks already Underway »

LotusScript Library to easily create XML files

Category
0
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:

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



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



Using this method, and Google Charts, here is an example of a report you could output using this method (hightly redacted of course)

A picture named M2

Comments

Gravatar Image2 - Were the changes above necessary to make this work? Something isn't right with my code (tried following the 2nd example above) and the file is not writing. It did once and I went back to format a little as it was closing out tags prematurely, etc. And now it won't write :(

Gravatar Image1 - Thank's Jeremy for code

I've made changes:
1) in constructor
replacesrc(0) = "&"
replacedes(0) = "&"
replacesrc(1) = """"
replacedes(1) = """
replacesrc(2) = "<"
replacedes(2) = "&lt;"
replacesrc(3) = ">"
replacedes(3) = "&gt;"
replacesrc(4) = "'"
replacedes(4) = "&apos;"

2) in property "InnerText"
Me.myInnerText = Replace( InnerText, replacesrc, replacedes )

3) in property "AddAttribute"
Me.myAttributes(AttName) = Replace( AttValue, replacesrc, replacedes )

Post A Comment