日期:2014-05-17 浏览次数:20467 次
System.IO.MemoryStream stream = new System.IO.MemoryStream();
byte[] bytes =System.Text.Encoding.Unicode.GetBytes("<客户 客户姓名=\"王五\" 客户代码=\"3\" 协议号=\"abc\" 额度=\"333\" 账户=\"3\" 品种=\"4\" />");
stream.Write(bytes, 0, bytes.Length);
stream.Position = 0L;
System.Xml.Linq.XDocument doc = System.Xml.Linq.XDocument.Load(stream);
doc.Element("客户").Add(new System.Xml.Linq.XAttribute("新属性", "100"));
string xml = doc.ToString();
string filename = @"c:\test.xml";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filename);
(xmlDoc.SelectSingleNode(@"//客户[@客户姓名='王五']") as XmlElement).SetAttribute("客户性别", "男");
xmlDoc.Save(filename);