documents:windows:powershell:powershell-008
差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン前のリビジョン | |||
| documents:windows:powershell:powershell-008 [2026/04/28 17:51] – k896951 | documents:windows:powershell:powershell-008 [2026/04/28 17:58] (現在) – Copilotに「お前のコードクラシカル(笑)」と煽られたのでPowerShell7.x用を用意した k896951 | ||
|---|---|---|---|
| 行 7: | 行 7: | ||
| Chat-GPTさん情報で、PowerShell 5.1系はスクリプトを UTF-8 BOM付 で保存しておく。こうしておかないとスクリプトのパースに失敗する事があるそうだ。\\ ※今回 xmlupdate.ps1 で実際に喰らった | Chat-GPTさん情報で、PowerShell 5.1系はスクリプトを UTF-8 BOM付 で保存しておく。こうしておかないとスクリプトのパースに失敗する事があるそうだ。\\ ※今回 xmlupdate.ps1 で実際に喰らった | ||
| ===== XML整形 ===== | ===== XML整形 ===== | ||
| + | |||
| + | ==== powershell 5.x シリーズ用 ==== | ||
| <code powershell xmlformatter.ps1> | <code powershell xmlformatter.ps1> | ||
| 行 39: | 行 41: | ||
| </ | </ | ||
| - | 入力サンプルXML | + | ==== powershell 7.x シリーズ用 ==== |
| + | |||
| + | <code powershell xmlformatter.ps1> | ||
| + | ## powershell -NoProfile -ExecutionPolicy Bypass -File xmlformatter.ps1 XMLファイル名 | ||
| + | |||
| + | param( | ||
| + | [Parameter(Mandatory = $true)] | ||
| + | [string] $InputPath | ||
| + | ) | ||
| + | |||
| + | Add-Type -AssemblyName System.Xml.Linq | ||
| + | |||
| + | if (Test-Path $InputPath) { | ||
| + | $base = [System.IO.Path]:: | ||
| + | $OutputPath = ([System.IO.Path]:: | ||
| + | } else { | ||
| + | Write-Host " | ||
| + | exit | ||
| + | } | ||
| + | |||
| + | ## 整形用にインデントを指示 | ||
| + | $settings = [System.Xml.Linq.SaveOptions]:: | ||
| + | |||
| + | ## XML読み込み | ||
| + | $xmldoc = [System.Xml.Linq.XDocument]:: | ||
| + | |||
| + | ## XML整形結果書き出し | ||
| + | $xmldoc.Save($OutputPath, | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | ==== 入力サンプルXML | ||
| <code xml sample.xml> | <code xml sample.xml> | ||
| 行 49: | 行 84: | ||
| </ | </ | ||
| - | 実行コマンドライン | + | ==== 実行コマンドライン |
| <code tt> | <code tt> | ||
| 行 55: | 行 90: | ||
| </ | </ | ||
| - | 実行結果(整形結果) | + | ==== 実行結果(整形結果) |
| <code xml sample.new.xml> | <code xml sample.new.xml> | ||
documents/windows/powershell/powershell-008.txt · 最終更新: by k896951
