gpt4 book ai didi

c# - 如何保存到 XML?

转载 作者:数据小太阳 更新时间:2023-10-29 02:27:32 25 4
gpt4 key购买 nike

我目前正在制作一个新的 WP7 应用程序,它应该允许用户填写两个文本框,单击一个按钮,然后使内容成为 .XML 文件的一部分。

此时,我正在使用以下代码:

string ItemName = ItemNameBox.Text;
string ItemAmount= ItemAmountBox.Text;

string xmlString = "<Items><Name>"+ItemName+"</Name></Item>";
XDocument document = XDocument.Parse(xmlString);
document.Root.Add(new XElement("Amount", ItemAmount));
string newxmlString = document.ToString();

MessageBox.Show(newxmlString);

现在,当我单击按钮时(因为这是在 onclick 按钮事件中),MessageBox 向我显示输出是正确的 XML 方式。

但是,我如何将其放入现有的 XML 架构中,该架构应该能够包含相当多的行(例如,待办事项/购物 list )?

最佳答案

这是我为 windows phone 编写的通用保护程序。

public static void SaveDataToIsolatedStorage(string filePath, FileMode fileMode, XDocument xDoc)
{
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
using (IsolatedStorageFileStream location = new IsolatedStorageFileStream(filePath, fileMode, storage))
{
System.IO.StreamWriter file = new System.IO.StreamWriter(location);
xDoc.Save(file);
}
}

关于c# - 如何保存到 XML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8148562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com