I've been doing quite a bit of searching/experimenting, and I know similar problems have been solved, but I'm struggling with this problem specifically and am reaching out for another pair of eyes. My goal is to parse an .xml file for names, alter the names, then save them. My .xml in brief:
<?xml version="1.0"?>
<menu>
<header>
<listname>Thing</listname>
<lastlistupdate>11/15/2011</lastlistupdate>
<listversion>1.1 Final</listversion>
<exporterversion>12.0</exporterversion>
</header>
<game name="My - Game (Japan) (Eu,Br)" index="true" image="0">
<description>My - Game (Japan) (Eu,Br)</description>
<cloneof></cloneof>
<crc>8B70CB5B</crc>
<manufacturer>Manufacturer</manufacturer>
<year>1997</year>
<genre>Shooter</genre>
<rating>ESRB - T (Teen)</rating>
<enabled>Yes</enabled>
</game>
<game name="Some Other Cool Game (Stuff) (Foo) (Bar)" index="" image="">
<description>Some Other Cool Game (Stuff) (Foo) (Bar)</description>
<cloneof></cloneof>
<crc>34F0EE5B</crc>
<manufacturer>Manufacturer</manufacturer>
<year>2000</year>
<genre>Shooter</genre>
<rating>ESRB - T (Teen)</rating>
<enabled>Yes</enabled>
</game>
I need to remove everything after the first "(" in the "game name" field and replace this content with "(USA)", so the first game name needs to change from:
My - Game (Japan) (Eu,Br)
Some Other Cool Game (Stuff) (Foo) (Bar)
To:
My - Game (USA)
Some Other Cool Game (USA)
I'm pretty close, and I'm able to get Powershell to print out the corrected names with:
[xml]$gameNames = Get-Content '.\myXML.xml' $gameNames.menu.game | foreach { $_.Name -replace '(.*', "(USA)" }
What I can't figure out is how to save hese new names in the "game name" nodes. I tried adding | Set-Content '.\myXML.xml'
to the end of my pipe, but this just overwrites the original .xml with the renamed game names and none of the original data.
*Edit: There is a "\" before the "(" in the last -replace line. It doesn't show up, but (without spaces), the line should look like:
-replace ' \ ( . * '