我正在raspberry pi上运行一个C#应用程序,在该应用程序中,我在启动时读取一次xml文件,然后每次使用以下代码更改该文件:
using System.Xml;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(settingsFileName);
第一次(在启动时)它总是有效的,但是当文件更改时,我总是得到这个异常:
Unhandled exception. System.Xml.XmlException: Root element is missing.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.Load(String filename)
配置文件如下所示:
<config>
<data1 seconds = "5000"></data1>
<data2 check = "16:00"></data2>