Skip to content

Commit dc92ca1

Browse files
committed
refactor(XMLDiff): enhance add operation logic for XML element positioning, use "after" and "prepend" instead of "before" in most cases>
1 parent 5283915 commit dc92ca1

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

XMLDiff/Program.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,23 @@ private static bool CompareElements(
643643
)
644644
{
645645
Logger.Debug($"Found match for '{GetElementInfo(originalChild)}' in the next child of '{GetElementInfo(modifiedElem)}'.");
646-
XElement addOp = new XElement(
647-
"add",
648-
new XAttribute("sel", GenerateXPath(originalChild, pathOptions)),
649-
new XAttribute("pos", "before")
650-
);
646+
XElement addOp;
647+
if (i > 0)
648+
{
649+
addOp = new XElement(
650+
"add",
651+
new XAttribute("sel", GenerateXPath(originalChildren[i - 1], pathOptions)),
652+
new XAttribute("pos", "after")
653+
);
654+
}
655+
else
656+
{
657+
addOp = new XElement(
658+
"add",
659+
new XAttribute("sel", GenerateXPath(originalElem, pathOptions)),
660+
new XAttribute("pos", "prepend")
661+
);
662+
}
651663
for (int l = j; l < k; l++)
652664
{
653665
var addedChild = modifiedChildren[l];

0 commit comments

Comments
 (0)