February 2019
Intermediate to advanced
626 pages
15h 51m
English
Nodes (elements, attributes, and so on) may be copied and moved between different XML documents. To bring a node from an external document into another, it must first be imported.
The following example creates two simple XML documents. The first (the xml variable) is the intended destination. The newNodes variable contains a set of elements that should be copied:
[Xml]$xml = @"
<?xml version="1.0"?>
<list type='numbers'>
<name>1</name>
</list>
"@ [Xml]$newNodes = @"
<root>
<name>2</name>
<name>3</name>
<name>4</name>
</root>
"@
Copying the name nodes requires each node to be selected in turn, imported into the original document, and added to the desired node:
foreach ($node in $newNodes.SelectNodes('/root/name')) ...Read now
Unlock full access