zoukankan      html  css  js  c++  java
  • C#操作XML存取创建XML

    using System.Xml; 

    #region 生成XML文档
     /// <summary>
     ///
     /// </summary>
     /// <param name="dr"></param>
     /// <returns></returns>
      public string MakeXml(DataRow dr)
      {
       
       
         
       XmlDocument xmlDoc = new XmlDocument();
       XmlProcessingInstruction objPI = xmlDoc.CreateProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
       xmlDoc.InsertBefore(objPI, xmlDoc.ChildNodes[0]);

       objPI = null;
       int indent=4;
       ArrayList arrError=new ArrayList();

       
       #region 团组资料
       XmlNode tzNode = xmlDoc.CreateElement("T_SWAP_DATA");
       tzNode.AppendChild(xmlDoc.CreateTextNode(System.Environment.NewLine));
       xmlDoc.AppendChild(tzNode);

       XmlNode tzNode1 = xmlDoc.CreateElement("T_QUERY_CONDITION");
       tzNode1.AppendChild(xmlDoc.CreateTextNode(System.Environment.NewLine));
       tzNode.AppendChild(tzNode1);

       this.createNode(indent + 4, tzNode1, "ST_LAST_NAME", fixString(dr["ST_LAST_NAME"]), false);

       this.createNode(indent + 4, tzNode1, "ST_FIRST_NAME", fixString(dr["ST_FIRST_NAME"]), false);

       this.createNode(indent + 4, tzNode1, "ST_FULL_NAME", fixString(dr["ST_FULL_NAME"]), false);

       this.createNode(indent + 4, tzNode1, "ST_SEX", fixString(dr["ST_SEX"]), false);

       this.createNode(indent + 4, tzNode1, "DT_BIRTHDAY", Convert.ToDateTime(dr["DT_BIRTHDAY"]).ToString("yyyy-MM-dd") , false);

       this.createNode(indent + 4, tzNode1, "ST_NATION", fixString(dr["ST_NATION"]), false);

       this.createNode(indent + 4, tzNode1, "ST_PASSPORT_NUM", fixString(dr["ST_PASSPORT_NUM"]), false);

       #endregion
       byte[] aFile=null;
                System.IO.MemoryStream    fs =new System.IO.MemoryStream();
       xmlDoc.Save("pass.xml");
       //xmlDoc.Save(fs);
       aFile=new byte[fs.Length ];
       fs.Read (aFile,0,Convert.ToInt32(fs.Length)  ) ;
       return System.Text.Encoding.UTF8.GetString(aFile);
      }

  • 相关阅读:
    GCD之各种派发
    Effective Objective-C 笔记之熟悉OC
    正则表达式之正向预查和负向预查
    vue的实例属性$refs
    vue的实例属性$options
    vue的实例属性$data
    vue的实例属性$el
    vue强制更新$forceUpdate()
    vue的extends的使用
    vue的mixins的使用
  • 原文地址:https://www.cnblogs.com/zlqblog/p/3658122.html
Copyright © 2011-2022 走看看