Permalink
Browse files

better handling of invalid XML files

  • Loading branch information...
1 parent ee43920 commit 3a3e80bc31120f299762f2545118a76dedb2a72f @crdx committed Oct 23, 2012
Showing with 15 additions and 5 deletions.
  1. +15 −5 src/PortableSettingsProvider.cs
@@ -67,14 +67,15 @@ private XmlDocument _rootDocument
}
catch (Exception)
{
- if (_xmlDocument.SelectSingleNode(_rootNodeName) != null)
- return _xmlDocument;
- _xmlDocument = new XmlDocument();
- _xmlDocument.AppendChild(_xmlDocument.CreateXmlDeclaration("1.0", "utf-8", string.Empty));
- _xmlDocument.AppendChild(_xmlDocument.CreateElement(_rootNodeName));
}
+
+ if (_xmlDocument.SelectSingleNode(_rootNodeName) != null)
+ return _xmlDocument;
+
+ _xmlDocument = GetBlankXmlDocument();
}
+
return _xmlDocument;
}
}
@@ -190,6 +191,15 @@ private XmlNode GetSettingsNode(string name)
return settingsNode;
}
+ public XmlDocument GetBlankXmlDocument()
+ {
+ XmlDocument blankXmlDocument = new XmlDocument();
+ blankXmlDocument.AppendChild(blankXmlDocument.CreateXmlDeclaration("1.0", "utf-8", string.Empty));
+ blankXmlDocument.AppendChild(blankXmlDocument.CreateElement(_rootNodeName));
+
+ return blankXmlDocument;
+ }
+
public void Reset(SettingsContext context)
{
_localSettingsNode.RemoveAll();

0 comments on commit 3a3e80b

Please sign in to comment.