Serialize a DOM tree in LotusScript?

I have a problem, that nor I nor any of my colleagues can’t solve easily. I have several classes that are passing objects/variables between them. On of them is handling Web Service request, and parsing the responses to a NotesDOMDocumentNode via the NotesDOMParser. The NotesDOMDocumentNode is passed returned, and are used in several places to extract information. But, I need to cache the response, so concurrent request with the same parameters are sped up.
To cache the response, I need to serialize the NotesDOMDocumentNode. At first, I thought this was easy, since there is a Serialize method on the NotesDOMParser. But no… You have to keep the original NotesDOMParser that parsed the raw XML data. The only solutions I can figure out are:

  • pass both the NotesDOMDocumentNode AND the original NotesDOMParser at all times
  • write my own Serialize method
  • pass the XML string only, and do the parsing at each method. I think this would be really slow…

To further illustrate what I want, here is an example:

Public Sub testDOMParser()
Dim parser As NotesDOMParser
Dim inStream As NotesStream
Dim node As NotesDOMDocumentNode
Set inStream = session.createStream()
Set parser = session.createDOMParser(inStream)
Call parser.process()
Set node = parser.document
Call serializeDocument(node)
End Sub
Public Sub serializeDocument(node As NotesDOMDocumentNode)
' Here, I want to do something like this:
Dim outStream As NotesStream
Dim parser As NotesDOMParser
Set outStream = session.createStream()
Set parser = session.createDOMParser(node, outStream)
parser.exitOnFirstFatalError = True
Call parser.serialize()
Print "Serialized tree: " + outStream.readText()
End Sub

Anyone who have had any experience with this and are willing to share their thoughts? We are talking R6 here…