当前位置:网站首页>C operation XML file
C operation XML file
2022-07-05 11:27:00 【Full stack programmer webmaster】
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(“ Student number ”); myTable.Columns.Add(“ full name ”); myTable.Columns.Add(“ Age ”); myTable.Columns.Add(“ Gender ”); 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[“ Student number ”] = number; myRow[“ full name ”] = name; myRow[“ Gender ”] = sex; myRow[“ Age ”] = 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 = “ Zhang San ”; XmlElement age = doc.CreateElement(“age”); age.InnerText = “21”; XmlElement sex = doc.CreateElement(“sex”); sex.InnerText = “ Woman ”; root.AppendChild(student); root.AppendChild(name); root.AppendChild(age); root.AppendChild(sex); doc.Save(xmlPath); } } }
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/109546.html Link to the original text :https://javaforall.cn
边栏推荐
- 【Oracle】使用DataGrip连接Oracle数据库
- 技术管理进阶——什么是管理者之体力、脑力、心力
- Modulenotfounderror: no module named 'scratch' ultimate solution
- Basic testing process of CSDN Software Testing Introduction
- Spark Tuning (I): from HQL to code
- 我用开天平台做了一个城市防疫政策查询系统【开天aPaaS大作战】
- Codeforces Round #804 (Div. 2)
- Stop saying that microservices can solve all problems!
- 以交互方式安装ESXi 6.0
- 2048游戏逻辑
猜你喜欢
COMSOL -- establishment of geometric model -- establishment of two-dimensional graphics
[advertising system] parameter server distributed training
[Oracle] use DataGrid to connect to Oracle Database
Lombok 同时使⽤@Data和@Builder 的坑,你中招没?
2022 Pengcheng cup Web
数据库三大范式
Harbor镜像仓库搭建
修复动漫1K变8K
Summary of thread and thread synchronization under window
7.2每日学习4
随机推荐
PHP中Array的hash函数实现
2022 Pengcheng cup Web
Cdga | six principles that data governance has to adhere to
管理多个Instagram帐户防关联小技巧大分享
Oneforall installation and use
Pytorch training process was interrupted
修复动漫1K变8K
How does redis implement multiple zones?
C#实现WinForm DataGridView控件支持叠加数据绑定
Bracket matching problem (STL)
FreeRTOS 中 RISC-V-Qemu-virt_GCC 的调度时机
Detailed explanation of DDR4 hardware schematic design
Solve the problem of slow access to foreign public static resources
百问百答第45期:应用性能探针监测原理-node JS 探针
idea设置打开文件窗口个数
How did the situation that NFT trading market mainly uses eth standard for trading come into being?
Deepfake tutorial
AutoCAD -- mask command, how to use CAD to locally enlarge drawings
Four departments: from now on to the end of October, carry out the "100 day action" on gas safety
[SWT component] content scrolledcomposite