Delete tag xml

I have a big XML file, and it looks like this for example:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<menu>

<game name="Name of game (Disk 2)" index="" image="">

<description>Adventure</description>

<manufacturer>Sharedata, Inc.</manufacturer>

<year>1981</year>

<genre>adventure</genre>

<rating>4</rating>

<enabled>Yes</enabled>

</game>

<game> another thousands game tags like that above </game>
</menu>

 

What I want is, if the word “Disk 2” is anywhere beetween <game> to </game> Then I want to remove the whole <game> tag ( frome <game to </game>. There are thousands of different game tags in the xml, so doing it manually would take some time. Tried to find a way to do it in Notepad++, but I could only mark lines that contained the word “Disk 2” and then delete just that line.

Using VI versus notepad, you could do the following:

To delete all lines containing “game” (remove the /d to show the lines that the command will delete):

:g/game/d

you can do this using XML object methods. you can read the XML file and cast it to [xml] type.

[xml]$XML = Get-Content -Path <xml file path>

The use XPath to find the XML element to remove.

$NodeToRemove = $XML.SelectNodes("//menu/game[contains(@name,'Disk 2')]")

Iterate through the results and remove the node from the parent element.

$ParentNode = $XML.SelectNodes("//menu")
Foreach($Node in $NoceToRemove)
{
 $ParentNode.RemoveChild($_)
}