How to remove nested in nested element from xml file

I need to Compare new names with name in XML file if name doesn’t match then I would like to remove that actor from XML file, if the name doesn’t existed then I would like to add it in.

$file = [xml]@’
<?xml version=”1.0″?>
<date>2019 Jan 01</date>
<name>Actor Name 1</name>

<name>Actor Name 2</name>


I try below code but it doesn’t work

$oldarray = $
"Actor 3",
"Actor Name 1"

Compare-Object -IncludeEqual -ReferenceObject $oldArray -DifferenceObject $newarray | Where-Object {

if($_.SideIndicator -eq "=>"){
$a = $file_data.appendChild($file.CreateElement("actor"))

if($_.SideIndicator -eq "<="){
$file_data.SelectSingleNode("//actor[text()='$w']") | foreach {[void]$_.parentnode.removechild($_)}


Please read and format your code properly so we can read it.