C#创建xml文件并写入内容
来源:互联网 发布:淘宝企业店铺要交费吗 编辑:程序博客网 时间:2024/05/22 10:59
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Xml;namespace xml{class Program{static void Main(string[] args){XmlDocument xmlDoc = new XmlDocument();//创建Xml声明部分,即<?xml version="1.0" encoding="utf-8" ?>XmlDeclaration Declaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);//创建根节点XmlNode rootNode = xmlDoc.CreateElement("root");//创建student子节点XmlNode testPointNode = xmlDoc.CreateElement("testPoint");//创建一个属性XmlAttribute testPointID = xmlDoc.CreateAttribute("TestPointID");testPointID.Value = "1";XmlAttribute caseID = xmlDoc.CreateAttribute("CaseId");caseID.Value = "TEST_0001";XmlAttribute name = xmlDoc.CreateAttribute("Name");name.Value = "111";//xml节点附件属性testPointNode.Attributes.Append(testPointID);testPointNode.Attributes.Append(caseID);testPointNode.Attributes.Append(name);rootNode.AppendChild(testPointNode);//附加根节点xmlDoc.AppendChild(rootNode);xmlDoc.InsertBefore(Declaration, xmlDoc.DocumentElement);//保存Xml文档xmlDoc.Save(@"d:\testPoint.xml");Console.WriteLine("已保存Xml文档");}}}转自:http://blog.sina.com.cn/s/blog_6cc1c52d01012lc3.html
0 0
- C#创建xml文件并写入内容
- C#创建xml文件并写入内容
- C# 如何创建一个xml文件?并写入指定内容?
- 创建文件并写入内容
- 创建xml并写入,读取xml内容
- C# 创建Excel并写入内容
- C# 创建Excel并写入内容
- ASP.NET创建文件并写入内容
- ASP.NET创建文件并写入内容
- ASP.NET创建文件并写入内容
- ASP.NET创建文件并写入内容
- ASP.NET创建文件并写入内容
- ASP.NET创建文件并写入内容
- java创建一个文件并写入内容
- 自动创建txt文件并写入内容
- c++创建txt文件,并写入内容
- dom4j 创建 并 写入 xml文件
- C# 创建,读取,写入 XML文件
- 正则表达式
- 第十四周项目2-二叉树排序树中查找的路径
- GNU M4宏处理器快速理解
- 第十四周项目1—验证折半查找
- This version does not support documents saved in the Xcode 8 format. Open this document with Xcode 8
- C#创建xml文件并写入内容
- 多线程编程之pthread_cond_wait
- 微信开发 (自动回复图片,自定义菜单)
- 第十五周项目3--B-数b,用括号法输出b数
- 第14周项目1-(3)验证二叉排序树相关算法
- 截取url参数
- Leetcode162. Find Peak Element
- XX cannot be resolved to a type 报错
- 第十四周 项目二 二叉树排序树中查找的路径