powershell xml 結合
powershell でxmlを結合。
$root ルートノード名
$out 出力ファイル名
$xmls 入力xmlファイル名の配列
function merge_root ($root, $out, $xmls) {
$m = "<" + $root + ">"
foreach ($f in $xmls){
[xml]$x = get-content $f
$top = $x.firstchild
$m += $top.innerxml
}
$m += "</" + $root + ">"
[xml]$x = $m
$x.save($out)
}
function merge ($out, $xmls) {
$m = ""
$root = "unknown"
foreach ($f in $xmls){
[xml]$x = get-content $f
$top = $x.firstchild
$root = $top.name
$m += $top.innerxml
}
$m += "</" + $root + ">"
[xml]$x = "<" + $root + ">" + $m
$x.save($out)
}