From Xojo Documentation


XMLNode.Clone(Deep as Boolean) As XMLNode

Supported for all project types and targets.

Duplicates the current node. The Deep parameter indicates whether to also duplicate all the child nodes. It returns an XMLNode.


The example code below uses this XML. Assign it to a constant called kXML:

 <?xml version="1.0" encoding="UTF-8"?>
 	<Team name="Seagulls">
 		<Player name="Bob" position="1B" />
 		<Player name="Tom" position="2B" />
 	<Team name="Pigeons">
 		<Player name="Bill" position="1B" />
 		<Player name="Tim" position="2B" />
 	<Team name="Crows">
 		<Player name="Ben" position="1B" />
 		<Player name="Ty" position="2B" />

Duplicate the first team node, change the team name and add it to the XML:

Dim xml As New XmlDocument(kXML)

Dim n As XmlNode = xml.DocumentElement.FirstChild

If n <> Nil Then
// Duplicate the first team
Dim dup As XmlNode = n.Clone(True)

// Change its name to "Eagles"
dup.SetAttribute("name", "Eagles")

// Add it to the XmlDocument

TextArea1.Text = xml.ToString
End If