Dynamic XML using LotusScript.Reading from the Memory stucture. Enjoy the code

Hi All,Here is the sample code I’d written to create dynamic xml documents in the memory.

Hope this code will be useful for beginers who wish to generate xml using LotusScript. You can modify the code as you need.

This code is created by using classes in Release 6.0.

Please feel free to write your comments.

Lotus Script Code to Generate In-Memory XML structure and reading from it


Option Public

Option Explicit

'Purpose of the Script.

'Sample program to show how an XML tree structure is generated

'in the Memory and walking through the in memory XML tree,instead of

'reading from the file system.

'Basic declarations.

Dim Session As NotesSession

Dim Db As NotesDatabase

Dim Coll As NotesDocumentCollection

Dim Doc As NotesDocument

'XML specific declarations.

Dim DomParser As NotesDOMParser

Dim MemoryStream As NotesStream 'The Stream generated in the memory.

Dim CorrectStream As NotesStream

Dim DomDoc As NotesDOMDocumentNode 'The Generated XML document note.

Dim ChunkData As Variant ’

Dim XmlText As String

Sub Initialize

Set Session=New NotesSession

Set Db=Session.CurrentDatabase

Set Coll=Db.UnprocessedDocuments

Set Doc=Coll.GetFirstDocument

Set MemoryStream=Session.CreateStream

On Error Goto Errhandler

Call GenerateXml()

MemoryStream.Position = 0

ChunkData=MemoryStream.Read

Set CorrectStream=Session.CreateStream

Forall b In ChunkData

	CorrectStream.WriteText(Chr$(b))

End Forall

CorrectStream.Position=0

XmlText=CorrectStream.ReadText

Set DomParser=Session.CreateDOMParser(XmlText)

'Now we've an XML document ready for furthur purposes like reading DTD etc.

DomParser.InputValidationOption=1 'This line explicitly looks for DTD	

DomParser.process

'Now we can Navigate throught the XML document 

 'that is created in the memory.

Set DomDoc=DomParser.Document

Msgbox "Reading InMemory XML documents Note Type :" & Cstr(domdoc.nodetype)

Exit Sub

Errhandler:

Msgbox DomParser.log()

Exit Sub

End Sub

Sub GenerateXml()

Call MemoryStream.WriteText("<?xml version='1.0' encoding='utf-8'?>")

Call MemoryStream.WriteText("<!DOCTYPE start SYSTEM 'C:\Dxl\dominox.dtd'>")

Call MemoryStream.WriteText("<start>")

Call MemoryStream.WriteText("<body>")

Call MemoryStream.WriteText(doc.GetItemValue("Body")(0))

Call MemoryStream.WriteText("</body>")

Call MemoryStream.WriteText("<subject>")

Call MemoryStream.WriteText(doc.GetItemValue("Subject")(0))

Call MemoryStream.WriteText("</subject>")	

Call MemoryStream.WriteText("</start>")

End Sub


Subject: THANK YOU!!! (but only for the client

Finally the solution for the client side.BUT… Running in by the server (scheduled) then the result is still crap.

Subject: Dynamic XML using LotusScript.Reading from the Memory stucture. Enjoy the code.

I did not enjoy having to debug your code. Part of the problem is that the error handler only works for parser errors, so an error somewhere else causes an error in the error handler.I did not understand the hard coded “C:\Dxl\dominox.dtd”. There is no such file on my system.

I did not understand the Chr$(b) thing. If you are hoping for UTF-8 encoded data, why do you convert everything to the platform character set?