zoukankan      html  css  js  c++  java
  • C#实现XML与DataTable互转

    C#中XML与datatable互换的两个函数:

    private string ConvertDataTableToXML(DataTable xmlDS)
    {
    MemoryStream stream
    = null;
    XmlTextWriter writer
    = null;
    try
    {
    stream
    = new MemoryStream();
    writer
    = new XmlTextWriter(stream, Encoding.Default);
    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();
    }
    }
    private DataSet 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);
    return xmlDS;
    }
    catch (Exception ex)
    {
    string strTest = ex.Message;
    return null;
    }
    finally
    {
    if (reader != null)
    reader.Close();
    }
    }
  • 相关阅读:
    Spring boot 梳理
    Spring boot 梳理
    Spring boot 梳理
    观察者模式
    设计模式原则
    Spring MVC上传文件
    Spring MVC视图解析器
    Spring MVC中Action使用总结
    Spring MVC控制器
    Java并发 两个线程交替执行和死锁
  • 原文地址:https://www.cnblogs.com/JuneZhang/p/2016068.html
Copyright © 2011-2022 走看看