という行の下にという行を追加するコードを作成してください"> という行の下にという行を追加するコードを作成してください"> という行の下にという行を追加するコードを作成してください">

PowerShellで、XMLファイルの<options customize="never" require-scripts="false"/>という行の下に<license file="/Applications/development/licenseAgreement.txt"></license>という行を追加するコードを作成してください

以下のPowerShellスクリプトは、指定されたXMLファイルの<options customize="never" require-scripts="false"/>という行の直後に新しい行を追加します。新しい行は<license file="/Applications/development/licenseAgreement.txt"></license>となります。

# XMLファイルのパスを指定します
$xmlFilePath = 'path_to_your_file.xml'

# XMLファイルを読み込みます
[xml]$xmlContent = Get-Content $xmlFilePath

# options要素を検索します
$optionsElement = $xmlContent.SelectSingleNode("//options[@customize='never' and @require-scripts='false']")

# options要素が存在する場合
if ($optionsElement -ne $null) {
    # 新しいlicense要素を作成します
    $newElement = $xmlContent.CreateElement("license")
    $newElement.SetAttribute("file", "/Applications/development/licenseAgreement.txt")

    # options要素の後に新しい要素を挿入します
    $optionsElement.ParentNode.InsertAfter($newElement, $optionsElement)

    # 変更をXMLファイルに保存します
    $xmlContent.Save($xmlFilePath)
    Write-Host "The new element has been added successfully."
} else {
    Write-Host "The specified options element was not found in the XML file."
}

このスクリプトは、指定された属性を持つoptions要素を検索し、その要素が見つかった場合にのみ新しいlicense要素を追加します。options要素が見つからない場合、スクリプトはメッセージを表示して終了します。このスクリプトを実行する前に、$xmlFilePath変数を適切なXMLファイルのパスに置き換えてください。また、XMLファイルが存在し、スクリプトがそのファイルに書き込むことができることを確認してください。このコードはXMLファイルを直接変更するため、事前にバックアップを取ることをお勧めします。