1
私は初心者です。このWebページでは、後になったことをするスクリプトを見つけましたが、特殊文字がある場合は*
と'
です。私のCSVファイルのcolumn2はXMLファイルに追加されません。Powershell:foreach-objectを使ったxmlの特殊文字は一致しません。
これは、これは私のCSVファイルはcolumn1のであり、私のXMLファイルが持っているものであるスクリプト
$c = Import-Csv C:\temp\testlinks.csv
Get-ChildItem C:\temp\output.xml | Foreach-Object {
# Out-String in the next line lets you work with a single string rather than an
# array of strings.
$xmldoc = (Get-Content $_.PSPath | Out-String)
# Loop through your CSV, updating $xmldoc with each pass
$c | Foreach-Object {
$xmldoc = $xmldoc -replace $_.column1name, ($_.column1name + " " + $_.column2name)
}
# Write the updated $xmldoc back to the original XML file's path
$xmldoc | Set-Content $_.PSPath
}
です:
<title lang="en">M*A*S*H</title>
<title lang="en">Who's The Boss?</title>
は
'-replace'は正規表現をサポートしています。理論的には、文字列にはエスケープする必要がある正規表現のメタ文字があります。 'regex :: Escape()'で最初にエスケープしてください。 – Matt
これは完璧に動作しました – Denz