[DXL] DOM Parser Error on AppendChild

I’m trying to clone and copy a node from a document to another throught DXL.My code successfully find the node and clones it, but it fails (“DOM Parser Error”) on AppendChild; the DOMParser.Log is empty.

This question was already asked in 2002, but I hope a solution was found meanwhile.

Here is the code (comments are in Italian, sorry)

’ Cerca l’attachment a un documento e lo copia in un altro via DXL

Sub DXLCopyAttachment(sourceDoc As NotesDocument, destDoc As NotesDocument, filename As String)

Dim session As New NotesSession

Dim db As NotesDatabase

Dim exporter As NotesDXLExporter

Dim domParser As NotesDOMParser

Dim sourceDOM As NotesDOMDocumentNode

Dim sourceRoot As NotesDOMElementNode

Dim destRoot As NotesDOMElementNode

Dim attachmentNode As NotesDOMNode

Dim i As Integer

Dim j As Integer

Dim sourceItems As NotesDOMNodeList

Dim sourceItem As NotesDOMNode

Dim attributes As NotesDOMNamedNodeMap

Dim attr As NotesDOMNode



On Error Goto ErrorTrap



Set db = session.CurrentDatabase

' Converte il documento sorgente in DXL

Set exporter = session.CreateDXLExporter(sourceDoc)

exporter.OutputDOCTYPE = False



Set domParser = session.CreateDOMParser(exporter)

Call exporter.Process



' Cerca l'allegato nel documento sorgente, esaminando solo i figli diretti della radice

Set sourceDOM = domParser.Document	

Set sourceRoot = sourceDOM.DocumentElement

Set sourceItems = sourceRoot.GetElementsByTagName("item")

Set attachmentNode = Nothing



For i = 1 To sourceItems.NumberOfEntries

	Set sourceItem = sourceItems.GetItem(i)

	Set attributes = sourceItem.Attributes

	For j = 1 To attributes.NumberOfEntries

		Set attr = attributes.GetItem(j)

		If attr.NodeName = "name" And attr.NodeValue = "$FILE" Then

			Set attachmentNode = sourceItem.Clone(True)

			Exit For

		End If

	Next

Next



' Se ho trovato l'attachment lo copio nel documento destinazione

If Not (attachmentNode Is Nothing) Then

	Dim importer As NotesDXLImporter

	

	Set importer = session.CreateDXLImporter

	' Converte il documento destinazione in DXL

	Call exporter.SetInput(destDoc)

	Call domParser.SetInput(exporter)

	Call exporter.Process

	

	Set destRoot = domParser.Document.DocumentElement

	' Allego l'attachment

	Call destRoot.AppendChild(attachmentNode)

	' Importo il documento modificato

	Call importer.SetInput(domParser)

	Call importer.SetOutput(db)

	Call domParser.Serialize

	Call importer.Process

End If

ErrorTrap:

Messagebox domParser.Log, , "Errore"

Exit Sub

End Sub

Subject: RE: [DXL] DOM Parser Error on AppendChild

Regrettably, you can’t append a node from one DOM tree into a second DOM tree. They have to both be children of the same NotesDOMParser.