任何方法,使XmlSerializer的输出XML中定义的顺序? [英] Any way to make XmlSerializer output xml in a defined order?

查看:155
本文介绍了任何方法,使XmlSerializer的输出XML中定义的顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我使用XmlSerializer的序列化和反序列化对象。 XML是在一个不确定的秩序是可以理解的,但比较对象的版本时,因为属性的顺序每次都不相同,使恼人产生。因此,例如我不能用正常的比较工具看到任何不同之处。

Currently I'm using XmlSerializer to serialize and deserialize an object. The xml is generated in an undefined order which is understandable but makes it annoying when comparing versions of the object, since the order of properties is different each time. So for instance I can't use a normal diff tool to see any differences.

有没有一种简单的方法来生成我以相同的顺序每次XML,而无需编写使用ReadXML和方法中WriteXML自己?我对班很多的属性,而现在每一次增加新的,所以将preFER到不用写,然后保持这种code。

Is there an easy way to generate my xml in the same order every time, without writing the ReadXml and WriteXml methods myself? I have a lot of properties on the class, and add new ones every now and again, so would prefer to not have to write and then maintain that code.

(C#.NET 2.0)

(C# .net 2.0)

推荐答案

本的XmlElement属性有一个<一个href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlelementattribute.order.aspx">order物业。您可以使用它作为一个开始。

The XmlElement attribute has an order property. You can use that as a start.

如果你需要找到在XML文件中的差异,你可能想看看这个

If you need to find the diff in Xml files, you might want to take a look at this.

这篇关于任何方法,使XmlSerializer的输出XML中定义的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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