1.引用命名空間:using System.Xml;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(GetTextByXML(Url.Content("~/XML/EMS/UpdatePrintData.xml")).ToString());
XmlNode printDatas = xmlDoc.SelectSingleNode("XMLInfo").SelectSingleNode("printDatas");//選擇要添加子節點的printDatas節點
XmlElement printData = xmlDoc.CreateElement("printData");//創建一個具有指定名稱的子節點
printData.SetAttribute("類別", "張三");//設置printData的屬性 及屬性值
XmlElement bigAccountDataId = xmlDoc.CreateElement("bigAccountDataId");
bigAccountDataId.InnerText = "";//設置該元素的值
printData.AppendChild(bigAccountDataId);//將該元素添加到printData子節點的尾部
printDatas.AppendChild(printData);//將printData節點添加到printDatas子節點的尾部
xmlDoc.Save("保存xml文件路徑");//保存xml文件
2./如果不想保存,只想讀取添加節點後的xml的數據
//將xml轉換成StringBuilder類型
var sb = new StringBuilder(xmlDoc.InnerXml);
var strXML = sb.ToString();