我有一个歌曲列表,我想使用智能设备(掌上电脑)将其输出到外部 XML 文件。
String path = GetAppDir();
string filePath = path + @"\output\songs.xml";
XmlWriter xmlOut = XmlWriter.Create(filePath, settings);
xmlOut.WriteStartDocument();
xmlOut.WriteStartElement("Songs");
foreach (Song songTmp in finalbasket)
{
xmlOut.WriteStartElement("Songs");
xmlOut.WriteAttributeString("Name", songTmp.SongName);
xmlOut.WriteElementString("Artist", songTmp.SongArtist);
xmlOut.WriteElementString("Price", Convert.ToString(songTmp.SongPrice));
xmlOut.WriteEndElement();
}
xmlOut.WriteEndElement();
xmlOut.Close();
该应用程序似乎在编写 xml 文档,但它总是空的。“finalbasket”列表中确实有项目。任何想法我做错了什么?