当前位置:网站首页>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
边栏推荐
- 华为设备配置信道切换业务不中断
- go语言学习笔记-分析第一个程序
- 我用开天平台做了一个城市防疫政策查询系统【开天aPaaS大作战】
- MySQL giant pit: update updates should be judged with caution by affecting the number of rows!!!
- Advanced technology management - what is the physical, mental and mental strength of managers
- Basic testing process of CSDN Software Testing Introduction
- FreeRTOS 中 RISC-V-Qemu-virt_GCC 的调度时机
- Stop saying that microservices can solve all problems!
- SLAM 01. Modeling of human recognition Environment & path
- In the last process before the use of the risk control model, 80% of children's shoes are trampled here
猜你喜欢
基于OpenHarmony的智能金属探测器
Go language learning notes - analyze the first program
COMSOL -- establishment of 3D graphics
Wechat nucleic acid detection appointment applet system graduation design completion (6) opening defense ppt
Stop saying that microservices can solve all problems!
Basic testing process of CSDN Software Testing Introduction
修复动漫1K变8K
Oneforall installation and use
How to make full-color LED display more energy-saving and environmental protection
Summary of thread and thread synchronization under window
随机推荐
COMSOL -- 3D casual painting -- sweeping
Codeforces Round #804 (Div. 2)
OneForAll安装使用
高校毕业求职难?“百日千万”网络招聘活动解决你的难题
Summary of thread and thread synchronization under window
Deepfake tutorial
How to make full-color LED display more energy-saving and environmental protection
Manage multiple instagram accounts and share anti Association tips
数据库三大范式
分类TAB商品流多目标排序模型的演进
Wechat nucleic acid detection appointment applet system graduation design completion (7) Interim inspection report
无密码身份验证如何保障用户隐私安全?
COMSOL -- establishment of geometric model -- establishment of two-dimensional graphics
Is it difficult to apply for a job after graduation? "Hundreds of days and tens of millions" online recruitment activities to solve your problems
Paradigm in database: first paradigm, second paradigm, third paradigm
Risc-v-qemu-virt in FreeRTOS_ Scheduling opportunity of GCC
【广告系统】增量训练 & 特征准入/特征淘汰
Huawei equipment configures channel switching services without interruption
解决readObjectStart: expect { or n, but found N, error found in #1 byte of ...||..., bigger context ..
Wechat nucleic acid detection appointment applet system graduation design completion (6) opening defense ppt