目前我交流#窗口工作表單應用程序,但我有以下問題:設定值
我已經在下面列出的xml:
<new>
<Company></Company>
<DateTime></DateTime>
<Message></Message>
<Status><Status>
</new>
<new>
<Company></Company>
<DateTime></DateTime>
<Message></Message>
<Status><Status>
</new>
<new>
<Company></Company>
<DateTime></DateTime>
<Message></Message>
<Status><Status>
</new>
<new>
<Company></Company>
<DateTime></DateTime>
<Message></Message>
<Status><Status>
</new>
<new>
<Company></Company>
<DateTime></DateTime>
<Message></Message>
<Status><Status>
</new>
我得到的數據等這樣的:
XDocument doc = XDocument.Load(Globals.pathNotifFile);
var notifDateTime = doc.Descendants("DateTime");
var message = doc.Descendants("Message");
var company = doc.Descendants("Company");
var sendStatus = doc.Descendants("Status");
var dateTimeCollection = new List<String>();
var messageCollection = new List<String>();
var companyCollection = new List<String>();
var statusCollection = new List<String>();
foreach (var dateTimeOfNotification in notifDateTime)
{
dateTimeCollection.Add(dateTimeOfNotification.Value);
}
foreach (var messages in message)
{
messageCollection.Add(messages.Value);
}
foreach (var companys in company)
{
companyCollection.Add(companys.Value);
}
foreach (var isSent in sendStatus)
{
statusCollection.Add(isSent.Value);
}
return Tuple.Create(dateTimeCollection, messageCollection, companyCollection, statusCollection);
而且我用xml文件
Tuple<List<String>, List<String>, List<String>, List<String>> t = GetDataFromFile();
List<String> dateTimeCollection = t.Item1;
List<String> messageCollection = t.Item2;
List<String> companyCollection = t.Item3;
List<String> statusCollection = t.Item4;
foreach (var notifDateTime in dateTimeCollection)
{
int index = dateTimeCollection.IndexOf(notifDateTime);
if (Int32.Parse(statusCollection[index]) == 1 || statusCollection[index] == string.Empty)
{
if (notifDateTime != string.Empty)
{
if (Convert.ToDateTime(notifDateTime) == DateTime.Now)
{
SendMessageToUser(messageCollection[index], companyCollection[index]);
}
}
}
}
的數據這樣做
後,在SendMessageToUser我發送郵件,我得到迴應1,2或3,但我的問題是關於讓在那裏我必須寫狀態的確切節點。我用寫狀態的功能是:
XmlDocument doc = new XmlDocument();
doc.LoadXml(Globals.pathNotifFile);
XmlNode commentsElement = doc.SelectSingleNode("Status");
commentsElement.InnerText = status.ToString();
doc.Save(Globals.pathNotifFile);
所以在doc.SelectSingleNode((「狀態」))我必須把選定的節點和更新。任何想法我怎麼能做到這一點
任何特別的原因,爲什麼你不反序列化的XML,以便對象,請在對象上所有的邏輯,序列化對象到XML?這會讓你想要實現的更輕鬆 –
我不知道如何,對不起。我仍然在學習,這是我瞭解處理XML數據的方式。你能告訴我如何? –
我更新了我的答案,向您展示序列化/反序列化的樣子 –