writexml readxml 格式不对
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Runtime.Serialization;
namespace testxmlsz
{
class Program
{
static void Main(string[] args)
{
myclass[] ms = { new myclass(1),new myclass(2),new myclass(3)};
XmlSerializer xsz = new XmlSerializer(typeof(myclass[]));
MemoryStream mstream = new MemoryStream();
xsz.Serialize(mstream, ms);
byte[] bs = mstream.ToArray();
string strxml = System.Text.Encoding.UTF8.GetString(bs,0,bs.Length);
byte[] bd = System.Text.Encoding.UTF8.GetBytes(strxml);
mstream =new MemoryStream(bd);
object o = xsz.Deserialize(mstream); }
}
[Serializable]
public class myclass:System.Xml.Serialization.IXmlSerializable,System.Runtime.Serialization.ISerializable
{
public myclass() { a = 0; }
public myclass(int temp) { a = temp; }
public int a;
#region IXmlSerializable 成员 public System.Xml.Schema.XmlSchema GetSchema()
{
throw new Exception("The method or operation is not implemented.");
} public void ReadXml(System.Xml.XmlReader reader)
{
this.a = System.Xml.XmlConvert.ToInt32(reader.ReadElementString());
} public void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteString(System.Xml.XmlConvert.ToString(a));
} #endregion #region ISerializable 成员 void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
} #endregion
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Runtime.Serialization;
namespace testxmlsz
{
class Program
{
static void Main(string[] args)
{
myclass[] ms = { new myclass(1),new myclass(2),new myclass(3)};
XmlSerializer xsz = new XmlSerializer(typeof(myclass[]));
MemoryStream mstream = new MemoryStream();
xsz.Serialize(mstream, ms);
byte[] bs = mstream.ToArray();
string strxml = System.Text.Encoding.UTF8.GetString(bs,0,bs.Length);
byte[] bd = System.Text.Encoding.UTF8.GetBytes(strxml);
mstream =new MemoryStream(bd);
object o = xsz.Deserialize(mstream); }
}
[Serializable]
public class myclass:System.Xml.Serialization.IXmlSerializable,System.Runtime.Serialization.ISerializable
{
public myclass() { a = 0; }
public myclass(int temp) { a = temp; }
public int a;
#region IXmlSerializable 成员 public System.Xml.Schema.XmlSchema GetSchema()
{
throw new Exception("The method or operation is not implemented.");
} public void ReadXml(System.Xml.XmlReader reader)
{
this.a = System.Xml.XmlConvert.ToInt32(reader.ReadElementString());
} public void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteString(System.Xml.XmlConvert.ToString(a));
} #endregion #region ISerializable 成员 void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
} #endregion
}
}
解决方案 »
- C#控件库项目如何由vs2010版本转换成vs2008版本的
- 求一则正则表达式,筛选出前面是为<br>或者为没有任何字符
- 表单代码: 如何提交到SQL2000数据库,请帖代码,给全分
- 关于线程间同步的问题,紧急求助!
- 如何写一个返回datatable的server sql2000存储过程,并且在asp.net程序c#语言中如何编写调用?
- 乱码,急啊!思归,速马等大侠出手啊,没分了,在线等,要不失业了
- 我想获取正在运行中的程序A,有几个正在操作系统中运行?
- 有谁知道csdn论坛c#版块前几天的哪个提供C#案例下载的ftp ?????????
- c#中这么实现图片的幻灯效果(分不够可加)
- 动态Radiobuttonlist
- C# 打印问题 高手请进
- .net GridView_PageIndexChanging分页问题
reader.Read(); //有问题
reader.ReadStartElement("Name"); //有问题,有可能读过其他元素,reader是只进的,不能后退
if (!reader.IsEmptyElement)
{
this._name = reader.ReadString();
reader.ReadEndElement();
}
//...给其它成员赋值