xml にデータを挿入しようとしています。これは、データを挿入した後の xml ファイルの現在の形式です。
<?xml version="1.0" encoding="utf-8"?>
<ApplicationData>
<Minutes>
</Minutes>
<Minute MinuteId="6" Title="Project6" Date="6" Time="Project6" Location="6" MinuteDocumentFile="Project6" />
<Minute MinuteId="6" Title="Project6" Date="6" Time="Project6" Location="6" MinuteDocumentFile="Project6" />
</ApplicationData>
以下のこのコードを使用して
XmlTextReader _xmlTextReader = new XmlTextReader(config.XMLPath);
XmlDocument _xmlDocument = new XmlDocument();
_xmlDocument.Load(_xmlTextReader);
//Note: Close the reader object to release the xml file. Else while saving you will get an error that it is
//being used by another process.
_xmlTextReader.Close();
XmlElement _minutesElement = _xmlDocument.CreateElement("Minute");
_minutesElement.SetAttribute("MinuteId", "6");
_minutesElement.SetAttribute("Title", "Project6");
_minutesElement.SetAttribute("Date", "6");
_minutesElement.SetAttribute("Time", "Project6");
_minutesElement.SetAttribute("Location", "6");
_minutesElement.SetAttribute("MinuteDocumentFile", "Project6");
_xmlDocument.DocumentElement.AppendChild(_minutesElement);
_xmlDocument.Save(config.XMLPath);
上記のコードは正常に動作しますが、私の課題は、以下に示す現在の xml 形式を達成しようとしていることです。
<?xml version="1.0" encoding="utf-8"?>
<ApplicationData>
<Minutes>
<Minute MinuteId="6" Title="Project6" Date="6" Time="Project6" Location="6" MinuteDocumentFile="Project6" />
<Minute MinuteId="6" Title="Project6" Date="6" Time="Project6" Location="6" MinuteDocumentFile="Project6" />
</Minutes>
</ApplicationData>
作成した「Minute」XmlElement を、「Minutes」要素の外側ではなく、「Minutes」要素内に格納したいと考えています。
ありがとう..