XMLDocument.ImportNode

From Xojo Documentation

Method

XMLDocument.ImportNode(foreignNode as XMLNode,[deep as Boolean]) As XMLNode

Supported for all project types and targets.

Copies a node from another XMLDocument into the current document.

Notes

If the optional parameter deep is True, ImportNode will import all the child nodes of foreignNode. After you import a node, you must then place it somewhere within the XMLDocument.

Example

The following XML is stored in a constant called kXML:

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

To copy the first team into a new XML document:

Var xml1 As New XmlDocument(kXml)
Var xml2 As New XmlDocument

Var root As XmlNode
root = xml2.AppendChild(xml2.CreateElement("League"))

Var importNode As XmlNode
importNode = xml2.ImportNode(xml1.DocumentElement.FirstChild, True)

root.AppendChild(importNode)

TextArea1.Value = xml2.ToString