1.创建一个文档
XmlDocument xmlDoc = new XmlDocument(); //创建xml文档
XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "GB2312", null); //设置xml头部信息
xmlDoc.AppendChild(dec); //加入到xml
XmlNode root = xmlDoc.CreateElement("TestAppointmentResponse");
xmlDoc.AppendChild(root);
XmlNode root1 = xmlDoc.SelectSingleNode("TestAppointmentResponse");
XmlElement returnCode = xmlDoc.CreateElement("returnCode");
returnCode.InnerText = "100";
root1.AppendChild(returnCode);
XmlElement flag = xmlDoc.CreateElement("flag");
flag.InnerText = "1";
root1.AppendChild(flag);
xmlDoc.AppendChild(root);
则生成
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<TestAppointmentResponse>
<returnCode>100</returnCode>
<flag>1</flag>
</TestAppointmentResponse>