一、读取XML信息
using System.Xml;
/// <summary>
/// 读取xml节点属性值
/// setxml(xml路径,节点路径,节点属性名)
/// </summary>
public static string getxml(string xml, string node, string name)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xml);
var root = xmlDoc.DocumentElement;//取到根结点
XmlElement node1 = (XmlElement)xmlDoc.SelectSingleNode(node);
return node1.GetAttribute(name).ToString();
}
二、修改XML信息
using System.Xml;
/// <summary>
/// 修改xml节点属性值
/// getxml(xml路径,节点路径,节点属性名,值)
/// </summary>
public static void setxml(string xml, string node, string name, string value)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xml);
var root = xmlDoc.DocumentElement;//取到根结点
XmlElement node1 = (XmlElement)xmlDoc.SelectSingleNode(node);
node1.SetAttribute(name, value);
xmlDoc.Save(xml);
}