将XML文件保存到指定的文件路径 [英] Save XML File To Specified File Path

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

问题描述

大家好,



我正在尝试将xml文件保存到特定文件

路径。我确实成功创建了xml文件,但没有

我想要它。



这就是我使用的:



Hi all,

I am trying to save an xml file to a specific file
path. I do succeed in creating the xml file, but not
where I want it.

This is what I used:

XmlTextWriter writer = new XmlTextWriter("test.xml", null);





请给予任何帮助!!



Please any help would be appriciated!!

推荐答案

那么,问题是什么?只需修改路径变量,如下所示:

So, what is the issue? Just modify the path variable as below:
string path = "C:\\test.xml";
XmlTextWriter writer = new XmlTextWriter(path , null);


看看这些:

MSDN:XmlDocument.Save方法 [ ^ ]

MSDN支持:如何使用.NET Framework SDK中的XmlDocument类修改和保存XML [ ^ ]

视频:编写XML文件 [ ^ ]



例如:

Have a look at these:
MSDN: XmlDocument.Save Method[^]
MSDN Support: How To Modify and Save XML with the XmlDocument Class in the .NET Framework SDK[^]
Video: Write a XML file[^]

For example:
//save xml file at the given location
xmlDoc.Save(@"E:\My Projects\Test\data.xml");


这个是最好的解决方案我发现保存xmldoc格式化为文件data.xml:



This one is the best solution i've found to save the xml "doc" well formatted to file "data.xml":

XmlDocument doc = new XmlDocument();
doc.LoadXml("<item><name>wrench</name></item>");
// Save the document to a file and auto-indent the output.
using (XmlTextWriter writer = new XmlTextWriter("data.xml", null)) {
    writer.Formatting = Formatting.Indented;
    doc.Save(writer);
}


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

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