XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(path);
XmlElement add = (XmlElement)xmlDoc.SelectSingleNode("//test/add[@key='password']");
add.SetAttribute("value","sos");
xmlDoc.Save(path);
xmlDoc.Load(path);
XmlElement add = (XmlElement)xmlDoc.SelectSingleNode("//test/add[@key='password']");
add.SetAttribute("value","sos");
xmlDoc.Save(path);
using System;
using System.IO;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.Collections;
using System.Data;
using System.Xml;
using System.Management;
using System.Net;
namespace ZZ
{
class ZZConsole
{
[STAThread]
static void Main(string[] args)
{
string strXml="<?xml version=\"1.0\"?>"
+"<Data>"
+"<Head>"
+"<Nodeid>1111</Nodeid>"
+"<Subid>2222</Subid>"
+"<Version>2004</Version>"
+"<Date>20040302</Date>"
+"<Time>101500</Time>"
+"</Head>"
+"<Body>"
+"<Code>01</Code>"
+"<Name>深圳</Name>"
+"<IdType>0</IdType>"
+"<Idno>110258740824082</Idno>"
+"</Body>"
+"</Data>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(strXml);
string vv;
XmlNodeList myNodes = doc.GetElementsByTagName("Version");
vv = myNodes[0].InnerText;
//修改
myNodes[0].InnerText = "123455";
Console.WriteLine(vv);
myNodes = doc.SelectNodes("//Version");
vv = myNodes[0].InnerText;
Console.WriteLine(vv);
//修改
myNodes[0].InnerText = "67890";
doc.Save("d:\\text.xml");
Console.ReadLine();
}
}
}