c# - VS2005.net 2.0 c# : Best way to create xml file

标签 c# xml

就节点等而言,在 .net 2.0 中创建 xml 文件的最佳方法是什么。我认为我不能使用 LINQ。任何代码示例或文章都会有帮助。

最佳答案

您最好的选择是使用 XmlTextWriter类。

这是一个非常基本的示例:

var writer = new XmlTextWriter("Foo.xml", Encoding.UTF8);
writer.WriteStartDocument();
writer.WriteStartElement("Foo");
writer.WriteAttributeString("hello", "world"); 
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();

这会给你:

<?xml version="1.0" encoding="utf-8"?>
<Foo hello="world" />

关于c# - VS2005.net 2.0 c# : Best way to create xml file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1330362/

相关文章:

c# - WinForm 查看 XML 文件

xml - 从 XQuery 3.0 中的多个输入返回多个值?

java - 使用 JAXB 2.x 基于 XSD 在运行时解析 XML

c# - 已安装 PagedList 包, Controller 出现 "missing assembly reference"错误

c# - .NET/C# 上有一种 isset() 吗?

c# - 在 C# 中保存绑定(bind)到 DataGrid 的自定义 sql 查询中的数据

xml - XPath没有得到任何节点

c# - 仅在需要时加载类的 byte[] 属性

c# - 使用 Dynamic LINQ 过滤子查询

xml - 从哪里获取 Google 搜索 XSD