Index: Ringtoets/Common/src/Ringtoets.Common.IO/Readers/ConfigurationReader.cs
===================================================================
diff -u -r77ae070cdceab659705f8e3e9d4a9788d7af7334 -re1714dc7e1c63c28c493be6dcb06b38bf1e1cb0e
--- Ringtoets/Common/src/Ringtoets.Common.IO/Readers/ConfigurationReader.cs (.../ConfigurationReader.cs) (revision 77ae070cdceab659705f8e3e9d4a9788d7af7334)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Readers/ConfigurationReader.cs (.../ConfigurationReader.cs) (revision e1714dc7e1c63c28c493be6dcb06b38bf1e1cb0e)
@@ -21,6 +21,8 @@
using System;
using System.IO;
+using System.Xml;
+using System.Xml.Linq;
using Core.Common.IO.Exceptions;
using Core.Common.Utils;
using Core.Common.Utils.Builders;
@@ -34,6 +36,8 @@
/// The type of calculation items read from XML.
public abstract class ConfigurationReader
{
+ protected readonly XDocument xmlDocument;
+
///
/// Creates a new instance of .
///
@@ -51,6 +55,8 @@
IOUtils.ValidateFilePath(xmlFilePath);
ValidateFileExists(xmlFilePath);
+
+ xmlDocument = LoadDocument(xmlFilePath);
}
///
@@ -68,5 +74,28 @@
throw new CriticalFileReadException(message);
}
}
+
+ ///
+ /// Loads an XML document from the provided .
+ ///
+ /// The file path to load the XML document from.
+ /// Thrown when the XML document cannot be loaded.
+ private static XDocument LoadDocument(string xmlFilePath)
+ {
+ try
+ {
+ return XDocument.Load(xmlFilePath, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo | LoadOptions.SetBaseUri);
+ }
+ catch (Exception exception)
+ when (exception is InvalidOperationException
+ || exception is XmlException
+ || exception is IOException)
+ {
+ string message = new FileReaderErrorMessageBuilder(xmlFilePath)
+ .Build(CoreCommonUtilsResources.Error_General_IO_Import_ErrorMessage);
+
+ throw new CriticalFileReadException(message, exception);
+ }
+ }
}
}
\ No newline at end of file