string sql = "select rentid from lesseeRent ";
DataTable dt= MDGL.DBUtility.SQLServerHelper.GetDataTable(CommandType.Text,sql);
//创建一个xml文档
XmlDocument xmlDoc = new XmlDocument();
//声明,一个节点
XmlNode xmlNode = xmlDoc.CreateNode(XmlNodeType.XmlDeclaration,"","");
xmlDoc.AppendChild(xmlNode);
//注释
XmlComment xmlComment = xmlDoc.CreateComment("rentID列表");
xmlDoc.AppendChild(xmlComment);
//创建根元素
XmlElement xmlEle = xmlDoc.CreateElement("rentIDList");
xmlDoc.AppendChild(xmlEle);
//创建子元素
XmlElement xmlEle2;
foreach(DataRow dr in dt.Rows)
{
xmlEle2 = xmlDoc.CreateElement("rentID");
XmlText xmlText = xmlDoc.CreateTextNode(dr["rentID"].ToString());
xmlEle2.AppendChild(xmlText);//子元素添加文本内容
xmlEle.AppendChild(xmlEle2);//父元素添加子元素
}
xmlDoc.Save("D:\\b.xml");//xml文档存储