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

你可能感兴趣的:(xml)