Eu fiz um script powershell para editar vários arquivos xml em uma pasta,
ele irá editar apenas o nó "descrição", mas por algum motivo o resultado final é que a entidade '
se tornou um% normal'
e o nó "cloneof" é dividido em duas linhas.
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)
}
algumas ideias? teoricamente, o resto do arquivo permanecerá intacto, certo?
o XML está cheio de seções como essa XML ORIGINAL
<game name="Addams Family, The - Pugsley's Scavenger Hunt (USA)" index="" image="">
<description>Addams Family, The - Pugsley'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 EDITED
<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>
Tags powershell