保存到XML文档 [英] saving to xml document

查看:190
本文介绍了保存到XML文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的尝试弄清楚如何创建一个 Windows Phone 7的应用程序,我想更新/保存具有以下功能的XML文件:

I am "trying" to figure out how to create a Windows Phone 7 application and I would like to update/save an xml file with the following function:

        XDocument xmlDoc = XDocument.Load("myApp.xml");

        xmlDoc.Element("ocd").Add(new XElement("vDetails", new XElement("itemName", this.tb_Name.Text),
            new XElement("Date", System.DateTime.Now.ToString()), new XElement("itemValue", "")));

        xmlDoc.Save("data.xml");



然而,xmlDoc.Save线给人一种错误:的System.Xml的最佳重载的方法匹配.Linq.XDocument.Save(System.Xml.XmlWriter)有一些无效的参数。

However the xmlDoc.Save line is giving an error: The best overloaded method match for "System.Xml.Linq.XDocument.Save(System.Xml.XmlWriter) has some invalid arguments.

什么我需要做的纠正呢?

What do I need to do to correct this?

推荐答案

您需要保存到独立存储(或者其他一些地方)获得独立存储您的应用程序,打开一个流文件,并保存到流:使用(VAR存储= IsolatedStorageFile.GetUserStoreForApplication())
{
使用

You need to save to isolated storage (or a few other places). Get the isolated storage for your application, open a stream to a file, and save to the stream:

using (var storage = IsolatedStorageFile.GetUserStoreForApplication())
{
    using (Stream stream = storage.CreateFile("data.xml"))
    {
        doc.Save(stream);
    }
}

这篇关于保存到XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆