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″?>
<data>
<title>Name</title>
<date>2019 Jan 01</date>
<actor>
<name>Actor Name 1</name>
<type>Actor</type>
<thumb>image.jpg</thumb>
</actor>

<actor>
<name>Actor Name 2</name>
<type>Actor</type>
<thumb>image.jpg</thumb>
</actor>

<genre>genre1</genre>
<genre>genre2</genre>
</data>
‘@

I try below code but it doesn’t work

$oldarray = $file.data.actor
$newarray=@(
"Actor 3",
"Actor Name 1"
)

Compare-Object -IncludeEqual -ReferenceObject $oldArray -DifferenceObject $newarray | Where-Object {
$w=$_.InputObject

if($_.SideIndicator -eq "=>"){
$a = $file_data.appendChild($file.CreateElement("actor"))
$a.AppendChild($file.CreateElement("name")).InnerText=$w.Trim()
$a.AppendChild($file.CreateElement("type")).InnerText="Actor"
}

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

}
}

Please read https://powershell.org/forums/topic/guide-to-posting-code-2/ and format your code properly so we can read it.