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

相关推荐
周杰伦fans10 小时前
C# 23种设计模式详解与示例
开发语言·设计模式·c#
未来之窗软件服务11 小时前
万象EXCEL开发(五)模拟excel行计算 ——东方仙盟练气期
xml·仙盟创梦ide·东方仙盟·万象excel
xb113212 小时前
C#——方法的定义、调用与调试
开发语言·c#
code bean12 小时前
【C#】以 BlockingCollection 为核心的多相机 YOLO 检测任务处理框架
c#
sun00770012 小时前
网络配置config.xml的android.mk解析
android·xml
时光追逐者13 小时前
一款专门为 WPF 打造的开源 Office 风格用户界面控件库
ui·开源·c#·.net·wpf
-可乐加冰吗16 小时前
SuperMap iObjects .NET 11i 二次开发(十五)—— 类型转换之面转点
visualstudio·c#·.net
ajassi200016 小时前
开源 C# 快速开发(十二)进程监控
开发语言·开源·c#
大飞pkz18 小时前
【设计模式】代理模式
开发语言·设计模式·c#·代理模式
sali-tec20 小时前
C# 基于halcon的视觉工作流-章40-OCR训练识别
开发语言·图像处理·算法·计算机视觉·c#·ocr