xml数据反序列化的差异 [英] difference in deserialization of xml data

查看:83
本文介绍了xml数据反序列化的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i有一个问题

我们将以下面的方式将xmlbytedata反序列化为对象



代码:

 deserialise( byte  [] xmlByteDate) 
{
XmlSerializer ds = new XmlSerializer( typeof (Company.Employee)) ;
MemoryStream memoryStream = new MemoryStream(xmlByteData);
Company.Employee emp = new Company.Employee();
emp =(Company.Employee)ds.Deserialize(memoryStream);
return \\ temp;
}





代码1 :(另一种方式)

 deserialise( byte  [] xmlData)
{
XmlSerializer ds = new XmlSerializer ( typeof (员工));
MemoryStream memoryStream = new MemoryStream(xmlData);
XmlTextReader reader = new XmlTextReader(memoryStream);
员工emp = new Employee();
emp =(Employee)ds.Deserialize(reader);
return \\ temp;

}







哪个更好并且通过添加xmltextreader有什么优点和缺点如果有的话





问候,

vishnu k。

解决方案

你可以参考这些链接来了解。



XML序列化和反序列化:第1部分 [ ^ ]



http://msdn.microsoft.com/en-us/library/ms731073%28v=vs.110%29。 aspx [ ^ ]


你必须看到性能来检查哪一个更有效率t。



还有一个额外的代码行将 MemoryStream 转换为 XmlTextReader 不是一个好主意,因为你可以直接将 MemoryStream 转换为 object 。 / BLOCKQUOTE>

Hi all,

i have a question that
we will deserialize an xmlbytedata to an object in below manner

code:

deserialise(byte[] xmlByteDate)
{
        XmlSerializer ds = new XmlSerializer(typeof(Company.Employee));
        MemoryStream memoryStream = new MemoryStream(xmlByteData);
        Company.Employee emp = new Company.Employee();
        emp = (Company.Employee)ds.Deserialize(memoryStream);
        return emp;
}



code 1: (another way)

deserialise(byte[] xmlData)
{
           XmlSerializer ds = new XmlSerializer(typeof(Employee));
            MemoryStream memoryStream = new MemoryStream(xmlData);
            XmlTextReader reader = new XmlTextReader(memoryStream);
            Employee emp = new Employee();
            emp = (Employee)ds.Deserialize(reader);
            return emp;

}




which is better and by adding xmltextreader what are advantages and disadvantages if any


with regards,
vishnu k.

解决方案

you can refer these links to find out.

XML Serialization and Deserialization: Part-1[^]

http://msdn.microsoft.com/en-us/library/ms731073%28v=vs.110%29.aspx[^]


You have to see the performance to check which one is more efficient.

Still, having one more extra line of code to convert MemoryStream to XmlTextReader is not a good idea, as you can directly convert MemoryStream to object.


这篇关于xml数据反序列化的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆