当前位置: 首页 > article >正文

C#操作Xml节点

见过不少人、经过不少事、也吃过不少苦,感悟世事无常、人心多变,靠着回忆将往事串珠成链,聊聊感情、谈谈发展,我慢慢写、你一点一点看......

1、增加节点

public static bool AppendChild(string filePath, string xPath, XmlNode xmlNode){
  
  	try	{
  
  		XmlDocument doc = new XmlDocument();		doc.Load(filePath);		XmlNode xn = doc.SelectSingleNode(xPath);		XmlNode n = doc.ImportNode(xmlNode, true);		xn.AppendChild(n);		doc.Save(filePath);		return true;	}	catch	{
  
  		return false;	}}

2、修改节点

public static bool UpdateNodeInnerText(string filePath, string xPath, string value){
  
  	try	{
  
  		XmlDocument doc = new XmlDocument();		doc.Load(filePath);		XmlNode xn = doc.SelectSingleNode(xPath);		XmlElement xe = (XmlElement)xn;		xe.InnerText = value;		doc.Save(filePath);	}	catch	{
  
  		return false;	}	return true;}

3、查询节点

public static XmlNodeList ReadNodes(string filePath, string xPath){
  
  	try	{
  
  		XmlDocument doc = new XmlDocument();		doc.Load(filePath);		XmlNode xn = doc.SelectSingleNode(xPath);		XmlNodeList xnList = xn.ChildNodes;  		return xnList;	}	catch	{
  
  		return null;	}}

关注我,不失联。有啥问题请留言。

感情恋爱合集https://blog.csdn.net/forever8341/category_12863789.html

职业发展故事https://blog.csdn.net/forever8341/category_12863790.html

常用代码片段https://blog.csdn.net/forever8341/category_12863793.html

程序开发教程https://blog.csdn.net/forever8341/category_12863792.html

自我备考经验 https://blog.csdn.net/forever8341/category_12863791.html

高阶高效代码https://blog.csdn.net/forever8341/category_12873345.html

金融语言解析https://blog.csdn.net/forever8341/category_12877262.html


http://www.kler.cn/a/512536.html

相关文章:

  • 自动化办公|使用Python重命名并移动文件到对应文件夹
  • 基于微信小程序的医院挂号预约系统ssm+论文源码调试讲解
  • 基于行为分析的企业内网安全防护系统设计
  • 【大模型】ChatGPT 高效处理图片技巧使用详解
  • 《Vue3 十》Vue 底层原理
  • [gpu驱动] H200 nvidia-fabricmanager-550升级到nvidia-fabricmanager-565报错,升级步骤
  • Android 13 动态显示隐藏 HomeButton,RecentsButton
  • 100条Linux命令汇总
  • 微信小程序之 如何使用全局变量将openid传到其他页面
  • 【Tortoise-ORM】 高级特性与实战
  • Linux内核编程(二十一)USB驱动开发
  • 【Java数据结构】Java对象的比较
  • python如何导出数据到excel文件
  • 京东api接口获得JD商品详情接口PHP调用演示示例
  • 12 分布式事务
  • 深入 Flutter 和 Compose 的 PlatformView 实现对比,它们是如何接入平台控件
  • Pandas 数据重命名:列名与索引
  • Linux容器(初学了解)
  • Chromium 132 编译指南 Mac 篇(三)- 配置 depot_tools
  • Bash语言的数据库交互