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