title: ForEach line of a list get the string, search for specific node in XML and delete the parent node using Powershell
body: <p>I have a list with strings which for each line there is a correspondent node in a XML file. All the parents need to be deleted in that XML.
  The script is roughly working but the result is not correct. And I'm getting some errors with the variable <code>$line</code> inside a Xpath query.
  I'm struggling to figure out what is happening with that variable.</p>
  
  <p><strong>romlist.txt:</strong></p>
  
  <pre><code>1941.zip
  llander.zip
  warrior.zip
  </code></pre>
  
  <p><strong>gamelist.xml:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
    &lt;gameList&gt;
        &lt;game id="46415" source="screenscraper.fr"&gt;
            &lt;path&gt;.aaa/bbb/warrior.zip&lt;/path&gt;
            &lt;name&gt;Warrior&lt;/name&gt;
            &lt;desc&gt;qweqwe&lt;/desc&gt;
            &lt;image&gt;./images/warrior-image.png&lt;/image&gt;
            &lt;rating&gt;0.7&lt;/rating&gt;
            &lt;releasedate&gt;19790101T000000&lt;/releasedate&gt;
            &lt;developer&gt;Tim Skelly&lt;/developer&gt;
            &lt;publisher&gt;Vectorbeam&lt;/publisher&gt;
            &lt;genre&gt;Fight / N/A&lt;/genre&gt;
            &lt;players&gt;2&lt;/players&gt;
            &lt;video&gt;./videos/warrior-video.mp4&lt;/video&gt;
        &lt;/game&gt;
        &lt;game id="39873" source="screenscraper.fr"&gt;
            &lt;path&gt;.ccc/ddd/1941.zip&lt;/path&gt;
            &lt;name&gt;1941 - Counter Attack&lt;/name&gt;
            &lt;desc&gt;asdasd&lt;/desc&gt;
            &lt;image&gt;./images/1941-image.png&lt;/image&gt;
            &lt;rating&gt;0.8&lt;/rating&gt;
            &lt;releasedate&gt;19900101T000000&lt;/releasedate&gt;
            &lt;developer&gt;Capcom&lt;/developer&gt;
            &lt;publisher&gt;Capcom&lt;/publisher&gt;
            &lt;genre&gt;Shoot'em up / Vertical / Shoot'em Up&lt;/genre&gt;
            &lt;players&gt;2&lt;/players&gt;
            &lt;video&gt;./videos/1941-video.mp4&lt;/video&gt;
        &lt;/game&gt;
        &lt;game id="46408" source="screenscraper.fr"&gt;
            &lt;path&gt;.eee/fff/sundance.zip&lt;/path&gt;
            &lt;name&gt;Sundance&lt;/name&gt;
            &lt;desc&gt;zxczxc&lt;/desc&gt;
            &lt;image&gt;./images/sundance-image.png&lt;/image&gt;
            &lt;rating&gt;0.5&lt;/rating&gt;
            &lt;releasedate&gt;19790101T000000&lt;/releasedate&gt;
            &lt;developer&gt;Tim Skelly&lt;/developer&gt;
            &lt;publisher&gt;Cinematronics&lt;/publisher&gt;
            &lt;genre&gt;N/A / Various&lt;/genre&gt;
            &lt;players&gt;2&lt;/players&gt;
            &lt;video&gt;./videos/sundance-video.mp4&lt;/video&gt;
        &lt;/game&gt;
        &lt;game id="46393" source="screenscraper.fr"&gt;
            &lt;path&gt;.ggg/hhh/llander.zip&lt;/path&gt;
            &lt;name&gt;Lunar Lander&lt;/name&gt;
            &lt;desc&gt;asdasd&lt;/desc&gt;
            &lt;image&gt;./images/llander-image.png&lt;/image&gt;
            &lt;rating&gt;0.9&lt;/rating&gt;
            &lt;releasedate&gt;19790101T000000&lt;/releasedate&gt;
            &lt;developer&gt;Atari&lt;/developer&gt;
            &lt;publisher&gt;Atari&lt;/publisher&gt;
            &lt;genre&gt;Various / N/A / Simulation&lt;/genre&gt;
            &lt;players&gt;1&lt;/players&gt;
            &lt;video&gt;./videos/llander-video.mp4&lt;/video&gt;
        &lt;/game&gt;
    &lt;/gameList&gt;
  </code></pre>
  
  <p><strong>POWERSHELL:</strong></p>
  
  <pre><code>$input = "gamelist.xml"
  $output = "gamelist_result.xml"
  $romlist = "romlist.txt"
  
  [xml]$xml = Get-Content -Path $input -Raw
  
  ForEach($line in Get-Content $romlist) {
      $rom = $xml.selectSingleNode('//game/path[contains(text(),line)]') | Select-Object -ExpandProperty "#text"
      ForEach($node in $xml.gameList.game | Where-Object {$_.path -eq $rom})
      {
      $xml.gameList.RemoveChild($node)
      }
  }
  
  $path = (join-path $pwd $output)
  $xml.Save($path)
  </code></pre>
  
  <p>If <code>$xml.selectSingleNode('//game/path[contains(text(),line)]')</code> we have no errors but the result is wrong.</p>
  
  <p>If <code>$xml.selectSingleNode('//game/path[contains(text(),$line)]')</code> we have some errors and the result is inverted, where the list is preserved instead of being deleted.</p>
  
  <p>I'd appreciate any help to fixing this problem</p>