Skip to content

fix(XMLPatch): support multiple sibling elements in replace operations#29

Closed
louga31 wants to merge 1 commit intochemodun:mainfrom
louga31:fix/replace-multiple-siblings
Closed

fix(XMLPatch): support multiple sibling elements in replace operations#29
louga31 wants to merge 1 commit intochemodun:mainfrom
louga31:fix/replace-multiple-siblings

Conversation

@louga31
Copy link

@louga31 louga31 commented Feb 22, 2026

Summary

  • ApplyReplace used replaceElement.Element(targetName) which only returns the first matching child element, silently dropping any additional siblings
  • Fixed to insert all child elements from the <replace> operation, preserving their order
  • Added logging to indicate when multiple siblings are inserted (e.g. "and 3 sibling(s)")

Problem

When a <replace> diff operation contains multiple sibling elements:

<replace sel="path/to/do_if[@value='...']">
  <do_if value="...">...</do_if>
  <do_elseif value="...">...</do_elseif>
  <do_elseif value="...">...</do_elseif>
</replace>

Only the first <do_if> was inserted — the <do_elseif> elements were silently dropped. This is a valid pattern in X4 diff patches where a single element is replaced with an if/elseif chain.

Fix

Instead of replaceElement.Element(targetName) (single element), the fix uses replaceElement.Elements().ToList() to collect all children, then inserts them in order using AddAfterSelf before removing the original target.

Test plan

  • Verified with X4 diff patches containing multi-sibling <replace> operations
  • Single-element replacements continue to work as before
  • Attribute and text node replacements are unaffected

The ApplyReplace method used replaceElement.Element(targetName) which
only returned the first matching child element, silently dropping any
additional siblings. This fix inserts all child elements from the
replace operation, preserving their order.

This is needed for X4 diff patches where a single element is replaced
with multiple siblings (e.g. a do_if followed by do_elseif chains).
Copy link
Owner

@chemodun chemodun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. But excuse me, in parallel several day ago made appropriate patch for the both utils.
Currently have possibility to publish it.

One more time thank and excuse.

@chemodun chemodun closed this Feb 22, 2026
@louga31 louga31 deleted the fix/replace-multiple-siblings branch February 22, 2026 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants