当前位置:网站首页>c#操作xml文件
c#操作xml文件
2022-07-05 11:23:00 【全栈程序员站长】
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml;
namespace delegatedemo { public class XmlClass { private string xmlPath; public XmlClass(string xmlPath) { this.xmlPath = xmlPath; }
public DataView GetXmlElement() { DataTable myTable = new DataTable(); DataRow myRow; myTable.Columns.Add(“学号”); myTable.Columns.Add(“姓名”); myTable.Columns.Add(“年龄”); myTable.Columns.Add(“性别”); XmlDocument doc = new XmlDocument(); doc.Load(xmlPath); XmlElement xmlElement = doc.DocumentElement; foreach (XmlNode node in xmlElement.ChildNodes) { string number = node.Attributes[“number”].Value; string age = node.SelectSingleNode(“Age”).InnerText; string name = node.SelectSingleNode(“Name”).InnerText; string sex = node.SelectSingleNode(“Sex”).InnerText; myRow = myTable.NewRow(); myRow[“学号”] = number; myRow[“姓名”] = name; myRow[“性别”] = sex; myRow[“年龄”] = age; myTable.Rows.Add(myRow); } return myTable.DefaultView; }
public void InsertXml() { XmlDocument doc = new XmlDocument(); doc.Load(xmlPath); XmlElement root = doc.DocumentElement; XmlElement student = doc.CreateElement(“student”); student.SetAttribute(“number”, “003”); XmlElement name = doc.CreateElement(“name”); name.InnerText = “张三”; XmlElement age = doc.CreateElement(“age”); age.InnerText = “21”; XmlElement sex = doc.CreateElement(“sex”); sex.InnerText = “女”; root.AppendChild(student); root.AppendChild(name); root.AppendChild(age); root.AppendChild(sex); doc.Save(xmlPath); } } }
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/109546.html原文链接:https://javaforall.cn
边栏推荐
- How can edge computing be combined with the Internet of things?
- POJ 3176-Cow Bowling(DP||记忆化搜索)
- 华为设备配置信道切换业务不中断
- NFT 交易市场主要使用 ETH 本位进行交易的局面是如何形成的?
- Guys, I tested three threads to write to three MySQL tables at the same time. Each thread writes 100000 pieces of data respectively, using F
- 我用开天平台做了一个城市防疫政策查询系统【开天aPaaS大作战】
- Evolution of multi-objective sorting model for classified tab commodity flow
- Lombok makes ⽤ @data and @builder's pit at the same time. Are you hit?
- regular expression
- 2022 Pengcheng cup Web
猜你喜欢

About the use of Vray 5.2 (self research notes)

Summary of thread and thread synchronization under window

如何让全彩LED显示屏更加节能环保

Three suggestions for purchasing small spacing LED display

Detailed explanation of DDR4 hardware schematic design

Wechat nucleic acid detection appointment applet system graduation design completion (8) graduation design thesis template

【Office】Excel中IF函数的8种用法

Lombok makes ⽤ @data and @builder's pit at the same time. Are you hit?

Wechat nucleic acid detection appointment applet system graduation design completion (6) opening defense ppt

Huawei equipment configures channel switching services without interruption
随机推荐
Four departments: from now on to the end of October, carry out the "100 day action" on gas safety
购买小间距LED显示屏的三个建议
Ziguang zhanrui's first 5g R17 IOT NTN satellite in the world has been measured on the Internet of things
I used Kaitian platform to build an urban epidemic prevention policy inquiry system [Kaitian apaas battle]
居家办公那些事|社区征文
Risc-v-qemu-virt in FreeRTOS_ Scheduling opportunity of GCC
不要再说微服务可以解决一切问题了!
Wechat nucleic acid detection appointment applet system graduation design completion (6) opening defense ppt
边缘计算如何与物联网结合在一起?
Evolution of multi-objective sorting model for classified tab commodity flow
数据库三大范式
comsol--三维图形随便画----回转
Process control
我用开天平台做了一个城市防疫政策查询系统【开天aPaaS大作战】
About the use of Vray 5.2 (self research notes)
[advertising system] parameter server distributed training
Lombok makes ⽤ @data and @builder's pit at the same time. Are you hit?
Codeforces Round #804 (Div. 2)
基于OpenHarmony的智能金属探测器
基础篇——REST风格开发