zoukankan      html  css  js  c++  java
  • 使用XmlWriter写XML文件





    private const string filename = "demo.xml"; static void Main(string[] args) { XmlTextWriter writer=new XmlTextWriter(filename,null); //进行输出格式缩进设置 writer.Formatting = Formatting.Indented; //写XML声明 writer.WriteStartDocument(); //写出<?name text>的形式 string PItext = "type='text/xsl' href='book.xsl'"; writer.WriteProcessingInstruction("xml-stylesheet", PItext); //写DOCTYPE声明 writer.WriteDocType("book", null, null, "<!ENTITY h 'hardcover'>"); //写注释 writer.WriteComment("这是xml注释行"); //写一个开始元素(根元素) writer.WriteStartElement("book"); //属性 writer.WriteAttributeString("genre","novel"); writer.WriteAttributeString("ISBN","1-234-4546"); //书名元素 writer.WriteElementString("title","XML大全"); ////Write the style element writer.WriteStartElement("style"); writer.WriteEntityRef("h"); writer.WriteEndElement(); writer.WriteElementString("price","23"); //写入CDATA writer.WriteCData("Prices 15% off!!!"); //关闭根元素 writer.WriteEndElement(); //结束编写 writer.WriteEndDocument(); //缓冲区的内容写入文件 writer.Flush(); writer.Close(); //声明XML文档并加载 XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = true; doc.Load(filename); //将XML内容显示在控制台 Console.Write(doc.InnerXml); Console.In.Read();

      

  • 相关阅读:
    git操作工作流
    http请求发生了两次(options请求)
    npm dose not support Node.js v10.15.3
    数据双向绑定页面无反应(angularjs)
    table样式的下拉框(angularjs)
    vue-router做路由拦截时陷入死循环
    js前台调用lodop打印
    vuejs2.0的生命周期解读
    Promise的一些相关讲解
    JAVA net 笔记
  • 原文地址:https://www.cnblogs.com/yxyht/p/2679171.html
Copyright © 2011-2022 走看看