以xml格式保存 [英] saving in xml format

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

问题描述

我正在尝试以xml格式保存.在程序的另一部分中,我正在做同样的事情,并且正在工作.我做错了事,我找不到它.也许如果我在这里发布某人会发现一些东西.请帮忙.这是代码.

i am trying to save in xml format. in another part of the program i am doing the same thing and it is working. im doing something wrong and i cannot find it. maybe if i posted here someone will spot something. please help. this is the code.

SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = "XML file|*.xml";

            dialog.Title = "Save scenario";
            dialog.FileName = nameText.Text;


            if (dialog.ShowDialog().Value)
            {
                viewModel.SaveScenario(dialog.FileName,timeline.TimelineElements,timeline.StartTime,timeline.EndTime);

                if (!string.IsNullOrEmpty(viewModel.scenarioTempLocationFile))
                {
                    using (TextWriter writer = new StreamWriter(viewModel.scenarioTempLocationFile))
                        writer.Write(dialog.FileName);

                    Application.Current.Shutdown(0);

                }
            }




打开保存的文件时说:
XML文档必须具有顶层元素.错误处理resource




when opening the saved file it is saying:
XML document must have a top level element. Error processing resource

推荐答案

您只是将一些文本保存在具有XML扩展名的文件中.它不是真正的XML文件.这就是您收到该错误的原因.
You are simply saving some text in a file with XML extension. It is NOT a real XML file. That is the reason you are getting that error.


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

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