• xml与datatable类型互换


    //已测

    private DataTable ConvertXMLToDataSet(string xmlData)
    {
      StringReader stream = null;
      XmlTextReader reader = null;
      try
      {
        DataSet xmlDS = new DataSet();
        stream = new StringReader(xmlData);
        reader = new XmlTextReader(stream);
        xmlDS.ReadXml(reader);
        DataTable dt = new DataTable();
        dt= xmlDS.Tables[0];

        return dt;
      }
      catch (Exception ex)
      {
        string strTest = ex.Message;
        return null;
      }
      finally
      {
        if (reader != null)
        reader.Close();
      }
    }

    //未测,用的也少了

    private string ConvertDataTableToXML(DataTable xmlDS)
    {
      MemoryStream stream = null;
      XmlTextWriter writer = null;
      try
      {
        stream = new MemoryStream();
        writer = new XmlTextWriter(stream, Encoding.UTF8);
        xmlDS.WriteXml(writer);
        int count = (int)stream.Length;
        byte[] arr = new byte[count];
        stream.Seek(0, SeekOrigin.Begin);
        stream.Read(arr, 0, count);
        UTF8Encoding utf = new UTF8Encoding();
        return utf.GetString(arr).Trim();
      }
      catch
      {
        return String.Empty;
      }
      finally
      {
        if (writer != null) writer.Close();
      }
    }

  • 相关阅读:
    134. Gas Station
    135. Candy
    137. Single Number II
    136. Single Number
    138. Copy List with Random Pointer
    140. Word Break II(hard)
    139. Word Break
    笔试面试知识点
    OA的一些概念
    实验记录贴 —— 账号同步实验 RTX 和 LDAP(AD域)
  • 原文地址:https://www.cnblogs.com/bingg0/p/4831482.html
Copyright © 2020-2023  润新知