Skip to content

Copy

Copies the current XML node and all its child nodes from the source XPath to the target XPath or target navigator.

1
myXml.Copy(sourceXPath: string, target: ( string | Xml )):void

Parameters

string sourceXPath
    XPath of the node to copy. Use "." to specify the current node.

( string | Xml ) target
    Target XPath or Xml instance to copy to.

Remarks

This method attempts to determine the type of the node being copied from the XML schema. If the relevant schema is found, the copy operation is performed based on the XML schema definitions. Otherwise, it copies only nodes with matching names. Copying based on XML schema definitions automatically resolves collection items and creates new nodes.

Both the source and the target node must exist; an error is thrown when either XPath selects nothing. When several nodes match, the first one is used.

Examples

Copy a simple value

1
$Xml.Copy('Customer/Name', 'BillingContact/Name');

Copy a complex node with its child nodes

1
2
// copies Name, Email and any other matching child node of Customer into BillingContact
$Xml.Copy('Customer', 'BillingContact');

Copy data parsed from a service response into the pool data

1
2
var customer = $Xml.Parse('<Customer><Name>John Smith</Name><Email>[email protected]</Email></Customer>');
customer.Copy('.', $Xml.SelectSingle('Customer'));

See Also