日期:2014-05-18  浏览次数:21115 次

xml.loadxml()后如何读取???
string text = "<root>XML内容.....</root>";
xml.LoadXML(text);
{一些修改xml內容的程序}

如何再將xml的內容读回text???
即:
text = "<root>XML修改后的内容.......</root>";

------解决方案--------------------
源码如下:
using System;
using System.Xml;
using System.IO;
class xmltest
{
static void Main()
{
 string oldxmltext = "<root><name>wang</name><age>26</age></root>";
XmlDocument xd = new XmlDocument();
xd.LoadXml(xmltext );
XmlNode xn = xd.DocumentElement;
XmlElement newnode = xd.CreateElement("address");
newnode.InnerText = "beijing";
xn.AppendChild(newnode );
StringWriter sw = new StringWriter();
xd.Save(sw);
string newxmltext = sw.ToString();
}
}