CopyNode method: XmlNode class
Syntax
CopyNode(&Node)
Description
Use the CopyNode method to copy a node specified by &Node and all of its child nodes into the current node, as a child node. The new node is appended to the end of the list of child nodes. The specified node can belong to a different XmlDoc.
If you just want to copy a top-level node, without copying its children, you can just create a new node with the name of the node you want.
Parameters
| Parameter | Description |
|---|---|
|
&Node |
Specify an already instantiated node that you want to copy. |
Returns
None.
Example
Suppose that your XmlDoc has the following structure:
<?xml version="1.0"?>
<myroot>
<child>
<subchild/>
</child>
</myroot>
The following PeopleCode copies the node child and copies it into another doc.
Local XmlDoc &inXMLDoc, &firstDoc;
Local XmlNode &childNode;
&firstDoc = CreateXmlDoc("<?xml version='1.0'?><myroot><child><subchild/></child><⇒
/myroot>");
&inXMLDoc = CreateXmlDoc("<?xml version='1.0'?><root/>");
&childNode = &firstDoc.DocumentElement.FindNode("/child");
&inXMLDoc.DocumentElement.CopyNode(&childNode);
The following is the new structure:
<?xml version="1.0"?>
<root>
<child>
<subchild/>
</child>
</root>