diff --git a/ICD.Common.Utils/Xml/AbstractGenericXmlConverter.cs b/ICD.Common.Utils/Xml/AbstractGenericXmlConverter.cs index 7325c41..04cbe0d 100644 --- a/ICD.Common.Utils/Xml/AbstractGenericXmlConverter.cs +++ b/ICD.Common.Utils/Xml/AbstractGenericXmlConverter.cs @@ -102,13 +102,13 @@ namespace ICD.Common.Utils.Xml public virtual T ReadXmlTyped(IcdXmlReader reader) { // Read into the first node - if (!reader.Read()) + if (reader.NodeType != XmlNodeType.Element && !reader.ReadToNextElement()) throw new FormatException(); T output = default(T); bool instantiated = false; - while (reader.NodeType != XmlNodeType.EndElement) + while (true) { if (!instantiated) { @@ -121,6 +121,10 @@ namespace ICD.Common.Utils.Xml output = Instantiate(); instantiated = true; + // Read the root attributes + while (reader.MoveToNextAttribute()) + ReadAttribute(reader, output); + // Read out of the root element if (!reader.Read()) throw new FormatException(); @@ -136,15 +140,13 @@ namespace ICD.Common.Utils.Xml switch (reader.NodeType) { - case XmlNodeType.Attribute: - ReadAttribute(reader, output); - break; - case XmlNodeType.Element: ReadElement(reader, output); - break; + continue; case XmlNodeType.EndElement: + // Read out of the end element + reader.Read(); return output; default: @@ -153,8 +155,6 @@ namespace ICD.Common.Utils.Xml break; } } - - return output; } /// @@ -164,8 +164,6 @@ namespace ICD.Common.Utils.Xml /// protected virtual void ReadAttribute(IcdXmlReader reader, T instance) { - // Skip the attribute - reader.Read(); } ///