List<Person> list = new List<Person>
{
new Person{Name=\"张三\",Age=20,Email=\"zs@zhansan.com\"},
new Person{Name=\"李四\",Age=30,Email=\"ls@lisi.com\"},
new Person{Name=\"王五\",Age=22,Email=\"ww@wangwu.com\"},
new Person{Name=\"赵柳\",Age=20,Email=\"xl@zhaoliou.com\"},
new Person{Name=\"玄武\",Age=20,Email=\"xw@xuanwu.com\"},
new Person{Name=\"白虎\",Age=20,Email=\"bh@baihu.com\"},
};
//实例化 Document对象
Document doc = new Document();
//增加一个 文档声明
Declaration declaration = doc.Create Declaration(\"1.0\", \"utf-8\", null);
//创建 文档根节点
Element element = doc.CreateElement(\"List\");
//添加到 文档中
doc.AppendChild( element);
//循环添加
for (int i = 0; i < list.Count; i++)
{
//创建根节点下的子节点
Element person = doc.CreateElement(\"Person\");
//创建子节点的属性ID
Attribute attribute = doc.CreateAttribute(\"id\");
//给属性值赋值
attribute.Value = (i + 1).ToString();
//添加到子节点中
person.Attributes.Append( attribute);
//添加Name节点
Element Name = doc.CreateElement(\"Name\");
//给Name文本赋值
Name.InnerText = list[i].Name;
//添加到Person节点下
person.AppendChild( Name);
//以下节点类似
Element Age = doc.CreateElement(\"Age\");
Age.InnerText = list[i].Age.ToString();
person.AppendChild( Age);
Element Email = doc.CreateElement(\"Email\");
Email.InnerText = list[i].Email;
person.AppendChild( Email);
element.AppendChild( person);
}
//创建文件保存在 文件夹中
string fileName = Server.MapPath(\"/ /List. \");
doc.Save(fileName);
继续阅读与本文标签相同的文章
网络黑客有哪些种类他们都有哪些行为
-
阿里云创业孵化事业部总经理李中雨:经阿里巴巴孵化一年,企业成长6-7倍。
2026-05-19栏目: 教程
-
阿里云学生服务器搭建网站(1)-购买阿里云学生服务器
2026-05-19栏目: 教程
-
提高云资源的利用效率,降低阿里云的成本支出
2026-05-19栏目: 教程
-
东方富海董事长陈玮:想要牛市,要大幅提升直投比例。
2026-05-19栏目: 教程
-
一个系统,搞定闲鱼服务端复杂问题告警-定位-快速处理
2026-05-19栏目: 教程
