123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Xml;
- using System.Data;
- namespace ETD.Frame
- {
- public class XmlTODatSet
- {
- /// <summary>
- /// xml转DataTable
- /// </summary>
- /// <param name="xmlDS"></param>
- /// <returns></returns>
- 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();
- }
- }
- /// <summary>
- /// XML转DataSet
- /// </summary>
- /// <param name="xmlData"></param>
- /// <returns></returns>
- 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();
- }
- }
- }
- }
|