Exemplo n.º 1
0
        /// <summary>
        /// 将TSchem类序列化为xml文件并保存
        /// </summary>
        /// <param name="path">文件保存路径</param>
        /// <param name="schem">待序列化的类</param>
        public void SaveXml(string path, TSchem schem)
        {
            XmlSerializer           xs       = new XmlSerializer(schem.GetType());
            XmlSerializerNamespaces ns       = new XmlSerializerNamespaces();
            XmlWriterSettings       settings = new XmlWriterSettings();

            settings.Encoding = Encoding.GetEncoding("gb2312");
            settings.Indent   = true;
            XmlWriter writer = XmlWriter.Create(path, settings);

            ns.Add("", "");
            xs.Serialize(writer, schem, ns);
            writer.Close();
        }
Exemplo n.º 2
0
 /// <summary>
 /// 保存文件
 /// </summary>
 /// <param name="schem">存储测试相关信息的类</param>
 /// <param name="path">文件保存路径</param>
 public void SaveFile(TSchem schem, string path)
 {
     try
     {
         XmlSerializer           xs       = new XmlSerializer(schem.GetType());
         XmlSerializerNamespaces ns       = new XmlSerializerNamespaces();
         XmlWriterSettings       settings = new XmlWriterSettings();
         settings.Encoding = Encoding.GetEncoding("gb2312");
         settings.Indent   = true;
         XmlWriter writer = XmlWriter.Create(path, settings);
         ns.Add("", "");
         xs.Serialize(writer, schem, ns);
         writer.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(), "Error");
     }
 }