From 117d348933bbc6f749e6c5b457b1070443c3a1af Mon Sep 17 00:00:00 2001 From: maurizuki <62178459+maurizuki@users.noreply.github.com> Date: Wed, 8 Nov 2023 15:17:34 +0100 Subject: [PATCH] Update ExchangeRatesParser.cs --- src/ECB.Data.ExchangeRates/ExchangeRatesParser.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/ECB.Data.ExchangeRates/ExchangeRatesParser.cs b/src/ECB.Data.ExchangeRates/ExchangeRatesParser.cs index 63790a6..ec97fde 100644 --- a/src/ECB.Data.ExchangeRates/ExchangeRatesParser.cs +++ b/src/ECB.Data.ExchangeRates/ExchangeRatesParser.cs @@ -22,6 +22,7 @@ // OTHER DEALINGS IN THE SOFTWARE. using System.Globalization; +using System.Xml; using System.Xml.Linq; namespace ECB.Data.ExchangeRates @@ -30,15 +31,10 @@ public class ExchangeRatesParser : IExchangeRatesParser { public IEnumerable Parse(string source) { - if (string.IsNullOrWhiteSpace(source)) return new List(); - var document = XDocument.Parse(source); - if (document.Root == null) return new List(); - - var genericNamespace = document.Root.GetNamespaceOfPrefix("generic"); - - if (genericNamespace == null) return new List(); + var genericNamespace = document.Root!.GetNamespaceOfPrefix("generic") + ?? throw new XmlException("Namespace of prefix 'generic' is missing."); var seriesKeyValueName = XName.Get("Value", genericNamespace.NamespaceName); var obsName = XName.Get("Obs", genericNamespace.NamespaceName);