Skip to content

Commit cf94be7

Browse files
committed
fix(XMLPatch): use XmlReader only to check diff xml, but not read, to prevent formatting(indentation) issue when elements from diff is inserted into the original
1 parent 409deb9 commit cf94be7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

XMLPatch/Program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ private static void ProcessSingleFile(string originalXmlPath, string diffXmlPath
215215
using (XmlReader reader = XmlReader.Create(diffXmlPath, diffReaderSettings))
216216
{
217217
try {
218-
diffDoc = XDocument.Load(reader);
218+
while (reader.Read()) {}
219219
Logger.Info($"Parsed diff XML: {diffXmlPath}");
220220
} catch (XmlSchemaValidationException ex) {
221221
Logger.Error($"Validation failed: {ex.Message}");
@@ -231,6 +231,7 @@ private static void ProcessSingleFile(string originalXmlPath, string diffXmlPath
231231
diffDoc = XDocument.Load(diffXmlPath);
232232
}
233233

234+
diffDoc = XDocument.Load(diffXmlPath);
234235
if (diffDoc == null)
235236
{
236237
Logger.Error("Diff XML root is null.");
@@ -263,7 +264,9 @@ private static void ProcessSingleFile(string originalXmlPath, string diffXmlPath
263264
var settings = new XmlWriterSettings
264265
{
265266
Indent = true,
266-
IndentChars = new string(' ', indent)
267+
IndentChars = new string(' ', indent),
268+
NewLineChars = "\r\n",
269+
NewLineHandling = NewLineHandling.Replace
267270
};
268271
using (var writer = XmlWriter.Create(outputXmlPath, settings))
269272
{

0 commit comments

Comments
 (0)