• xml创建


      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文档存储
    View Code
     //写xml
                string sql = "select rentid from lesseeRent ";
               DataTable dt= MDGL.DBUtility.SQLServerHelper.GetDataTable(CommandType.Text,sql);
               //创建一个xml文档
               XmlDocument xmlDoc = new XmlDocument();
               StringBuilder str = new StringBuilder();
            
               str.Append("<?xml version=\"1.0\" ?>");
               str.Append("<rentList>");
               foreach (DataRow dr in dt.Rows)
               {
                   str.Append("<rentID>");
                   str.Append(dr["rentID"].ToString());
                   str.Append("</rentID>");
               }
               str.Append("</rentList>");
               xmlDoc.LoadXml(str.ToString());
               xmlDoc.Save("D:\\a.xml");
    View Code
  • 相关阅读:
    STL——pair
    STL——stack
    Python学习之编程基础
    开学第一课,课课有总结
    DNS域名解析
    FTP文件传输服务
    DHCP原理及配置
    Linux中配置网卡
    indoe与block解析
    Linux系统安全管理
  • 原文地址:https://www.cnblogs.com/zhaolijing910/p/3124003.html
Copyright © 2020-2023  润新知