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();
    }

  • 相关阅读:
    Android Studio 的 10 个你非常有可能不知道的技巧
    SSH框架的基本整合
    Spring Boot 配置类1-配置类流程
    Spring Boot web容器启动
    Tomcat介绍
    微服务演进史
    SpringBoot异常报告器
    SpringBoot Profile源码介绍
    SpringBoot Environment使用
    Spring Aware原理
  • 原文地址:https://www.cnblogs.com/mahongbo/p/1401399.html
Copyright © 2011-2022 走看看