当前位置:网站首页>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
边栏推荐
猜你喜欢
R3live series learning (IV) r2live source code reading (2)
How to introduce devsecops into enterprises?
Detailed explanation of MATLAB cov function
[advertising system] incremental training & feature access / feature elimination
Pytorch training process was interrupted
基于OpenHarmony的智能金属探测器
高校毕业求职难?“百日千万”网络招聘活动解决你的难题
How to make full-color LED display more energy-saving and environmental protection
Harbor image warehouse construction
【爬虫】wasm遇到的bug
随机推荐
[JS] extract the scores in the string, calculate the average score after summarizing, compare with each score, and output
基础篇——基础项目解析
7.2 daily study 4
POJ 3176-Cow Bowling(DP||记忆化搜索)
项目总结笔记系列 wsTax KT Session2 代码分析
四部门:从即日起至10月底开展燃气安全“百日行动”
2022 Pengcheng cup Web
我用开天平台做了一个城市防疫政策查询系统【开天aPaaS大作战】
Sklearn model sorting
修复动漫1K变8K
Deepfake tutorial
COMSOL--三维图形的建立
Wechat nucleic acid detection appointment applet system graduation design completion (7) Interim inspection report
Startup process of uboot:
如何通俗理解超级浏览器?可以用于哪些场景?有哪些品牌?
COMSOL -- 3D casual painting -- sweeping
阻止浏览器后退操作
Huawei equipment configures channel switching services without interruption
Redis如何实现多可用区?
Lombok 同时使⽤@Data和@Builder 的坑,你中招没?