zoukankan      html  css  js  c++  java
  • ASP.NET创建xml文件

     protected void WriteGiftInfoXml()
    {
                XmlDocument XDoc = new XmlDocument();
                XDoc.LoadXml("<GiftInfo></GiftInfo>");
                //设置版本信息
                XmlDeclaration xmldecl;
                xmldecl = XDoc.CreateXmlDeclaration("1.0", "utf-8", null);

                XmlElement root = XDoc.DocumentElement;
                XDoc.InsertBefore(xmldecl, root);

                //设置根节点
                XmlElement newGiftInfo = XDoc.DocumentElement;
                //创建礼品ID的节点
                XmlElement newGiftId = XDoc.CreateElement("GiftId");
                newGiftId.InnerText = "1001";     
                newGiftInfo.AppendChild(newGiftId);

                //创建礼品分类ID的节点
                XmlElement newCategoryId = XDoc.CreateElement("CategoryId");
                newCategoryId.InnerText = "Bless";       //礼品分类ID
                newGiftInfo.AppendChild(newCategoryId);


                XmlTextWriter tw = new XmlTextWriter(NewGiftFileAddress + GiftId + ".xml", System.Text.Encoding.UTF8);
                XDoc.WriteContentTo(tw);
                tw.Close();
    }

  • 相关阅读:
    G-sensor驱动分析
    写i2c_client驱动的两种方式
    TP分析
    JAVA基础知识要点
    springboot-线程池简单使用
    java 实现好看的图形验证码
    正则表达式校验15/18位生份证-JAVA版
    springboot2.X集成HttpClient 发送HTTPS 请求
    linux-修改时区时间
    springboot2.X 在项目启动后执行一段自定义代码
  • 原文地址:https://www.cnblogs.com/mahongbo/p/1401399.html
Copyright © 2011-2022 走看看