Fix XML formatting in batch insert and after clear operations

Two bugs caused tag concatenation (e.g. `</item><item`):
- Insert-BeforeElement: place new node before trailing whitespace, not before the preceding newline
- Get-ContainerChildIndent: check for Element children instead of HasChildNodes to correctly detect empty containers after clear-*

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Nick Shirokov
2026-02-11 19:39:07 +03:00
parent a9b7a90672
commit 2d0835ba17
+10 -6
View File
@@ -961,7 +961,7 @@ function Insert-BeforeElement($container, $newNode, $refNode, $childIndent) {
$trailing = $container.LastChild
if ($trailing -and ($trailing.NodeType -eq 'Whitespace' -or $trailing.NodeType -eq 'SignificantWhitespace')) {
$container.InsertBefore($ws, $trailing) | Out-Null
$container.InsertBefore($newNode, $ws) | Out-Null
$container.InsertBefore($newNode, $trailing) | Out-Null
} else {
$container.AppendChild($ws) | Out-Null
$container.AppendChild($newNode) | Out-Null
@@ -1223,12 +1223,16 @@ function Get-DataSetName($dsNode) {
}
function Get-ContainerChildIndent($container) {
$ci = Get-ChildIndent $container
if (-not $container.HasChildNodes) {
$settingsIndent = Get-ChildIndent $container.ParentNode
$ci = $settingsIndent + "`t"
$hasElements = $false
foreach ($ch in $container.ChildNodes) {
if ($ch.NodeType -eq 'Element') { $hasElements = $true; break }
}
if ($hasElements) {
return Get-ChildIndent $container
} else {
$parentIndent = Get-ChildIndent $container.ParentNode
return $parentIndent + "`t"
}
return $ci
}
# --- 6. Load XML ---