domParser - Copy one node to another domParser

Hi,

I am looking for a solution to copy one NotesDOMNode from one DOMparser object to another one. I’d like to be able to copy a childA from DOMparser1 into parentB node in DOMparser2. Any ideas how to achieve that?

Thierry

Subject: domParser - Copy one node to another domParser

You can’t copy as such. There is a Clone method, but it returns a “parentless” copy in the same document. Get a handle on the node you want to copy as an element node, then create a matching node in the target parser’s Document. (Element nodes have to be created at the Document level.)

Set targetNodeChild = parser_b.CreateElementNode(sourceNodeChild.TagName)

Once the element has been created, you can set its attributes.

Dim attrs As NotesDOMNamedNodeMap

Set attrs = sourceNodeChild.Attributes

Dim numAttrs As Integer

numAttrs = attrs.NumberOfEntries

Dim i As Integer

For i = 1 To numAttrs

Call targetNodeChild.SetAttribute(attrs(i).Name, attrs(i).Value)

Next

Depending on the node, you may also need to create and append a text node to represent the data contained in the node. Then get a handle on the target parent as a NotesDOMNode object (or a superclass, such as a NotesDOMElementNode) and use AppendChild to attach the new node. (The neat thing about DOM methods is that they’re pretty much universal – you’d use the same methods to modify an HTML document using JavaScript with minor language-specific modifications.)