Talking back XML with Domino

After years of having to create XML streams in Domino by concatenating strings, I wonder why it took so long before I had to create an XML response with LotusScript using the R6 DomParser. We have had the ability to use Java to do this, and I think that is the main reason why I never got around to using the new LS parser classes.

The code rests in an agent that is the endpoint of a Javascript XML call and is supposed to return an XML response with either a success message or a string to display using the alert() method. Using the new parser classes (in my case the DomParser) is absurdly easy and ALOT more reliable than string concatenation.

Dim domParser As NotesDOMParser
Dim nodeDoc As NotesDOMDocumentNode
Dim nodeNode As NotesDOMElementNode
Dim nodeNode2 As NotesDOMElementNode
Dim nodeText As NotesDOMTextNode
Dim streamOut As NotesStream
Set domParser = s.CreateDOMParser
Set streamOut = s.CreateStream
strOut = "Success"
' insert some logic to decide on the strOut variable content
Set nodeDoc = domParser.Document
Set nodeNode = nodeDoc.CreateElementNode("response")
Call nodeDoc.appendChild(nodeNode)
Set nodeNode2 = nodeDoc.CreateElementNode("resultstring")
Call nodeNode.appendchild(nodeNode2)
Set nodeText = nodeDoc.CreateTextNode(strOut)
Call nodeNode2.appendChild(nodeText)
' to get xml doc we need to output to a notesStream
Call domParser.setOutput(streamOut)
Call domParser.Serialize ' xml doc contents into stream
Print {content-type:text/xml;charset=utf-8} 'REQUIRED or browser will see HTML
Print streamOut.ReadText 'the text of the xml document

Why did it take so long before I used these classes? Still not sure.

Comments are closed.