How to create DOM Tree from scratch and save it to file?

Hi,

i try to create a XML DOM Tree with data of some documents and serialize the tree to a file. I’m really stuck, perhaps you can help me out. I am not able to create a file. There’s nothing on my c: drive after the operation. Looks like I’m completely on the wrong way.

Here is my code. Thanks for any hints or advice.

Thomas

Sub Initialize
Dim se As New NotesSession
Dim domparser As NotesDOMParser
Dim domdoc As NotesDOMDocumentNode
Dim stream As NotesStream
Dim node1 As NotesDOMElementNode
Dim node2 As NotesDOMElementNode

	 'Create DOMParser and add some nodes
	 Set domParser=se.CreateDOMParser
	 Set domdoc = domparser.Document.CreateDocumentNode
	 Set node1 = domdoc.CreateElementNode("Test")
	 Set node2 = domdoc.CreateElementNode("Hallo")
	 Call domdoc.appendChild(node1)
	 Call node1.appendChild(node2)
	 
	 'Serialize DOMTree
	 Set stream = se.CreateStream
	 If Stream.Open( "c:\Text.xml" ) Then
	 		 Call stream.Truncate
	 		 Call domparser.SetOutput(stream)
	 		 Call domparser.serialize()
	 		 Call stream.close()
	 End If

End Sub

.lotusscript { font-family: sans-serif; font-size: 9pt; color: black; } .ls-comment { color: green; } .ls-quote { color: black; } .ls-datatype { color: black; } .ls-operator { color: blue; } .ls-keyword { color: blue; } .ls-statement { color: blue; } .ls-function { color: blue; } .ls-class { color: black; } .ls-constant { color: purple; }
Sub Initialize Dim se As New NotesSession Dim domparser As NotesDOMParser Dim domdoc As NotesDOMDocumentNode Dim stream As NotesStream Dim node1 As NotesDOMElementNode Dim node2 As NotesDOMElementNode 'Create DOMParser and add some nodes Set domParser=se.CreateDOMParser Set domdoc = domparser.Document.CreateDocumentNode Set node1 = domdoc.CreateElementNode("Test") Set node2 = domdoc.CreateElementNode("Hallo") Call domdoc.appendChild(node1) Call node1.appendChild(node2) 'Serialize DOMTree Set stream = se.CreateStream If Stream.Open( "c:\Text.xml" ) Then Call stream.Truncate Call domparser.SetOutput(stream) Call domparser.serialize() Call stream.close() End If End Sub
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.

Subject: How to create DOM Tree from scratch and save it to file?

I think the parser already has a document node. You create a second document node, and you add children to it. When you serialize, you get the parser’s original document node, which has no children. So your stream is empty. To fix this, remove .CreateDocumentNode from your code. Add the children to the original document node.

Subject: Thank you very much

Thank you Rod. It works great now.Somehow I expected that you would know what went wrong with my stuff.