保存到 xml 文档

发布于 2024-10-03 21:37:21 字数 540 浏览 1 评论 0原文

我正在“尝试”弄清楚如何创建Windows Phone 7 应用程序,并且我想使用以下功能更新/保存 xml 文件:

        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.保存行给出错误:“System.Xml.Linq.XDocument.Save(System.Xml.XmlWriter) 的最佳重载方法匹配有一些无效参数。

我需要做什么来纠正这个问题?

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");

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泪冰清 2024-10-10 21:37:21

您需要保存到隔离存储(或其他一些地方)。获取应用程序的独立存储,打开文件流,然后保存到流中:

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

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);
    }
}
深府石板幽径 2024-10-10 21:37:21

Windows Phone 开发人员博客深入讨论了应用程序执行模型。

我认为区分应用程序“关闭”和应用程序被逻辑删除很重要。

申请关闭只是
用户按下的结果
硬件后退按钮足够多次
向后浏览页面
您的申请,过去
应用程序的首页。

应用程序停用发生在
不同的应用程序控制
前景 - 例如,
来电,启动
选择器,或用户按下
视窗按钮。在这两种情况下,您的
应用程序将被停用(不
关闭)。在我们进入之前
停用事件的微妙之处,
让我们确保我们都明白这一点
停用后,您的应用程序
被终止(最后)。它是
就这么简单;你的代码无法运行
背景,因此你的
应用程序被终止。然而,
与关闭的应用程序不同,
停用的应用程序得到
墓碑。不要混淆,一个
墓碑化应用程序的进程仍然
被终止。但与封闭式不同的是
应用程序,WP 运行的地方
系统会删除任何痕迹
应用程序,当应用程序
停用,WP 操作系统
存储的记录(墓碑)
应用程序的状态。基本上,WP
操作系统保留了墓碑
成为一部分的应用程序
手机的应用程序后台堆栈,
这是一本能够使
使用硬件后退按钮
增强导航功能。

应用程序执行模型

至于测试,一个想法可能是重构代码并添加记录各种事件点,例如关闭或被逻辑删除等。

The Windows Phone developer blog goes talks application execution model in great depth.

I think it is important to distinguish between application 'closing' and an application being tombstoned.

Application Closing is simply the
outcome of the user pressing the
hardware Back button enough times to
navigate backwards through the pages
of your application, past the
application’s first page.

Application Deactivated occurs when a
different application takes control of
the foreground - for example, an
incoming phone call, launching a
chooser, or the user pressing the
Windows button. In both cases, your
application will be deactivated (not
closed). Before we step into the
subtleties of the Deactivated event,
let’s make sure we all understand that
upon Deactivation, your application
gets terminated (at the end). It's
that simple; your code can’t run in
the background, therefore your
application gets terminated. However,
unlike an application that is closed,
a deactivated application gets
tombstoned. Don’t get confused, a
tombstoned application’s process still
gets terminated. But unlike a closed
application, where the WP operating
system removes any trace of the
application, when an application is
deactivated, the WP operating system
stores a record (a tombstone) of the
application's state. Basically, the WP
operating system keeps a tombstone of
the application that becomes part of
the phone’s application back-stack,
which is a journal that enables the
use of the hardware Back button to
enhance navigation functionality.

Application Execution Model

As for testing, an idea may be to refactor the code and add logging for various event points like closing or being tombstoned etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文