PowerShell : remove XML node

I'm trying to remove node "A"

$xml=@"
<migrationManifests>
  <file>A</file>
  <file>B</file>
  <file>C</file>
  <file>D</file>
  <file>E</file>
  <file>F</file>
</migrationManifests>
"@

$data = -join("/migrationManifests[@file='A']")

$node = $xml.SelectSingleNode($data) 
$null = $node.ParentNode.RemoveChild($node)
    
$xml.migrationManifests.file

And I get this error:

You cannot call a method on a null-valued expression.

Any ideas how to do it?


Solution 1:

You are almost there - but @ selects an attribute, not a node:

try changing

$node = $xml.SelectSingleNode($data) 

to

$node = $xml.SelectSingleNode('//migrationManifests/file[.="A"]')