Powershell 脚本不断删除“实体

Powershell 脚本不断删除“实体

我已经编写了一个 powershell 脚本来编辑文件夹中的多个 xml 文件,它将仅编辑“描述”节点,但由于某种原因,最终的结果是实体'变为正常'并且“cloneof”节点分成两行。

Get-ChildItem .\ *.xml -recurse | % {
echo "Editing file" $_.Name
$xml = [xml](Get-Content $_.fullname)
$xml.SelectNodes("//description") | ForEach-Object {
$string = $_.InnerText

if ($string -like "*(*") {
    $string = $string.substring(0, $string.Indexof("(")-1)

    if ($string -like '*,*') 
        {
        $article = $string.Substring($string.LastIndexOf(','))

        if ([string]$article -eq ", The") {
            $string = $article.Substring(2) + " " + $string.Substring(0, $string.LastIndexOf(","))
        }
        elseif ([string]$article -eq ", A") {
            $string = $article.Substring(2) + " " + $string.Substring(0, $string.LastIndexOf(","))
        }
        elseif ([string]$article -eq ", L'") {
            $string = $article.Substring(2) + $string.Substring(0, $string.LastIndexOf(","))
        }
        elseif ([string]$article -like "*-*") {
            $string = $article.Substring(2, $article.IndexOf("-")-2) + $string.Substring(0, $string.LastIndexOf(",")) + $article.substring($article.IndexOf("-")-1)
        }


      else {
            echo "No article renaming needed for:"
            echo $article
            echo $string
           }

        }
    }

$_.'#text' = $string
} 
$xml.save($_.FullName)
}

有什么想法吗?理论上文件的其余部分将保持不变,对吗?

XML 充满了像这样的部分 ORIGINAL XML

<game name="Addams Family, The - Pugsley&apos;s Scavenger Hunt (USA)" index="" image="">
    <description>Addams Family, The - Pugsley&apos;s Scavenger Hunt (USA)</description>
    <cloneof></cloneof>
    <crc>6B8D777D</crc>
    <manufacturer>Ocean</manufacturer>
    <year>1993</year>
    <genre>Platform</genre>
    <rating>Other - NR (Not Rated)</rating>
    <enabled>Yes</enabled>
</game>

已编辑 XML

<game name="Addams Family, The - Pugsley's Scavenger Hunt (USA)" index="" image="">
<description>The Addams Family - Pugsley's Scavenger Hunt</description>
<cloneof>
</cloneof>
<crc>6B8D777D</crc>
<manufacturer>Ocean</manufacturer>
<year>1993</year>
<genre>Platform</genre>
<rating>Other - NR (Not Rated)</rating>
<enabled>Yes</enabled>

相关内容