我创建了一个XML文件,其中包含以下基本信息:
<?xml version="1.0" encoding="UTF-8"?>
<MailSettings>
<To>some@email.com</To>
<From>another@email.com</From>
<Server>smtp.email.com</Server>
<Port>25</Port>
<Subject>E-mail subject</Subject>
</MailSettings>
我尝试使用以下代码读取每个标记:
public static void ReadXml(string send)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(AppDomain.CurrentDomain.BaseDirectory + "\\MailSettings.xml");
XmlNodeList xnList = doc.SelectNodes("/MailSettings");
foreach (XmlNode xn in xnList)
{
string To = xn["To"].InnerText;
string From = xn["From"].InnerText;
string Server = xn["Server"].InnerText;
string Port = xn["Port"].InnerText;
string Subject = xn["Subject"].InnerText;
WriteErrorLog("Sending an e-mail with the following settings");
WriteErrorLog("To: " + To + " From: " + From + " Server: " + Server + " Port: " + Port + " Subject: " + Subject);
}
}
然而,它失败并出现以下错误:
&#34;由于未处理的异常,该流程终止。&#34; 异常信息:System.Xml.XmlException 堆: 在System.Xml.XmlTextReaderImpl.Throw(System.String,System.String) 在System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace() 在System.Xml.XmlTextReaderImpl.ParseDocumentContent() 在System.Xml.XmlLoader.Load(System.Xml.XmlDocument,System.Xml.XmlReader,Boolean) 在System.Xml.XmlDocument.Load(System.Xml.XmlReader) 在System.Xml.XmlDocument.LoadXml(System.String) 在AEMKeepAlive.Library.ReadXml(System.String) 在AEMKeepAlive.AEMKeepAlive.ServiceMonitor() 在System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object,Boolean) 在System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object,Boolean) 在System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object) 在System.Threading.ThreadHelper.ThreadStart()
我不确定自己做错了什么,似乎无法让它发挥作用。