October 2017
Intermediate to advanced
440 pages
11h 47m
English
Modifying an existing node, whether it is an attribute or an element value, can be done by assigning a new value:
[XDocument]$xDocument = @"
<?xml version="1.0"?>
<items>
<item name='Fridge'>
<category>Appliancse</category>
</item>
<item name='Cooker'>
<category>Appliances</category>
</item>
</items>
"@
$xDocument.Element('items').
Elements('item').
Where( { $_.Attribute('name').Value -eq 'Fridge' } ).
ForEach( { $_.Element('category').Value = 'Appliances' } )
Modifying the value of an attribute uses the same syntax:
[XDocument]$xDocument = @"
<?xml version="1.0"?>
<list name='letters'>
<name>1</name>
</list>
"@
$xDocument.Element('list').Attribute('name').Value = 'numbers'
If the attribute does not ...
Read now
Unlock full access