我写的有问题 麻烦哪位给一下:)/// <summary>
/// serialize the current object into xml string
/// </summary>
/// <returns>the xml document string</returns>
public string XmlSerialize()
{
XmlSerializer serializer = new XmlSerializer(InnerDataTable.DataSet.GetType());
MemoryStream ms = new MemoryStream();
StreamWriter writer = new StreamWriter(ms, Encoding.UTF8); serializer.Serialize(writer, InnerDataTable.DataSet);
writer.Flush();
writer.Close();
writer.Dispose(); UTF8Encoding encoding = new UTF8Encoding();
string xml = new string(encoding.GetChars(ms.GetBuffer()));
ms.Dispose(); return xml;
}
/// <summary>
/// Deserialize a object by a xml string
/// </summary>
/// <param name="xml">the xml string</param>
/// <returns>the object</returns>
public static DataSet XmlDeserialize(string xml)
{
char[] array = xml.ToCharArray();
byte[] buf = new byte[array.Length * 2];
for( int i = 0; i < array.Length; i++)
{
buf[i * 2] = (byte)((array[i] & 0xFF00) >> 8);
buf[i * 2 + 1] = (byte)(array[i] & 0x00FF);
}
MemoryStream ms = new MemoryStream(buf);
XmlSerializer serializer = new XmlSerializer(typeof(DataSet));
DataSet ds = (DataSet)serializer.Deserialize(ms);
ms.Dispose(); return ds;
}
/// serialize the current object into xml string
/// </summary>
/// <returns>the xml document string</returns>
public string XmlSerialize()
{
XmlSerializer serializer = new XmlSerializer(InnerDataTable.DataSet.GetType());
MemoryStream ms = new MemoryStream();
StreamWriter writer = new StreamWriter(ms, Encoding.UTF8); serializer.Serialize(writer, InnerDataTable.DataSet);
writer.Flush();
writer.Close();
writer.Dispose(); UTF8Encoding encoding = new UTF8Encoding();
string xml = new string(encoding.GetChars(ms.GetBuffer()));
ms.Dispose(); return xml;
}
/// <summary>
/// Deserialize a object by a xml string
/// </summary>
/// <param name="xml">the xml string</param>
/// <returns>the object</returns>
public static DataSet XmlDeserialize(string xml)
{
char[] array = xml.ToCharArray();
byte[] buf = new byte[array.Length * 2];
for( int i = 0; i < array.Length; i++)
{
buf[i * 2] = (byte)((array[i] & 0xFF00) >> 8);
buf[i * 2 + 1] = (byte)(array[i] & 0x00FF);
}
MemoryStream ms = new MemoryStream(buf);
XmlSerializer serializer = new XmlSerializer(typeof(DataSet));
DataSet ds = (DataSet)serializer.Deserialize(ms);
ms.Dispose(); return ds;
}
解决方案 »
- 请问如何改变分区方案中对应的文件组
- 简单JS提问
- FCKeditor2_6_3没有权限
- 怎么禁用WebPartZone组件中的关闭和最小化按钮
- 我是新人
- ASP.NET调用API
- 未将对象引用设置到对象的实例。 ??? 是什么意思啊 高手请进 静候祥解
- 初学问题再发贴:用户控件的调用问题,请高手再指点一下(已经第十天了)
- 在ASP.NET里如何判断一个文件是否存在?
- ???如何让ADO.NET异步执行???
- 在ASPNET中DATAREADER所使用的返回值是什么?
- ASP.NET生成的作者域明明是我的名字(中文)却无法生效,在作者域手工敲一遍我的名字马上就生效,但是再把原来自动生成的名字拷回去马上
/// serialize the current object into xml string
/// </summary>
/// <returns>the xml document string</returns>
public string XmlSerialize()
{
MemoryStream ms = new MemoryStream();
StreamWriter writer = new StreamWriter(ms, Encoding.UTF8);
InnerDataTable.DataSet.WriteXml(writer);
writer.Flush();
writer.Close();
writer.Dispose(); UTF8Encoding encoding = new UTF8Encoding();
string xml = new string(encoding.GetChars(ms.GetBuffer()));
ms.Dispose(); return xml;
}怎么反序列化呢?