努力したWiki

推敲の足りないメモ書き多数

ユーザ用ツール

サイト用ツール


documents:windows:powershell:powershell-008

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
documents:windows:powershell:powershell-008 [2026/04/28 17:51] k896951documents: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:
 </code> </code>
  
-入力サンプル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]::GetFileNameWithoutExtension($InputPath) 
 +    $OutputPath = ([System.IO.Path]::GetFullPath($base) + ".new.xml"
 +} else { 
 +    Write-Host "ファイルなし" 
 +    exit 
 +
 + 
 +## 整形用にインデントを指示 
 +$settings = [System.Xml.Linq.SaveOptions]::None 
 + 
 +## XML読み込み 
 +$xmldoc = [System.Xml.Linq.XDocument]::Load($InputPath) 
 +  
 +## XML整形結果書き出し 
 +$xmldoc.Save($OutputPath, $settings) 
 + 
 +</code> 
 + 
 + 
 +==== 入力サンプルXML ==== 
  
 <code xml sample.xml> <code xml sample.xml>
行 49: 行 84:
 </code> </code>
  
-実行コマンドライン+==== 実行コマンドライン ====
  
 <code tt> <code tt>
行 55: 行 90:
 </code> </code>
  
-実行結果(整形結果)+==== 実行結果(整形結果) ====
  
 <code xml sample.new.xml> <code xml sample.new.xml>
documents/windows/powershell/powershell-008.txt · 最終更新: by k896951

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki