如何使用XmlSerializer指定XmlAttributes的顺序 [英] How to specify the order of XmlAttributes, using XmlSerializer
问题描述
XmlElement 具有订单" 属性,在使用XmlSerializer进行序列化时,可以使用该属性指定属性的精确顺序(相对于彼此)./p>
XmlElement has an "Order" attribute which you can use to specify the precise order of your properties (in relation to each other anyway) when serializing using XmlSerializer.
public class bookingList
{
[XmlElement(Order = 1)]
public string error { get; set; }
[XmlElement(Order = 2)]
public int counter { get; set; }
[XmlElement(ElementName = "booking", Order = 3)]
public List<booking> bookings = new List<booking>();
}
XmlAttribute 是否有类似的东西?我只想从类似的东西中设置属性的顺序
Is there a similar thing for XmlAttribute? I just want to set the order of the attributes from something like
<MyType end="bob" start="joe" />
到
<MyType start="joe" end="bob" />
这只是为了提高可读性,这确实是我自己的利益.
This is just for readability, my own benefit really.
推荐答案
您不必这样做,因为XML中的属性没有顺序(XML建议的第3.1节说:请注意,标签或空元素标签无关紧要.").
You don't, as attributes have no order in XML (section 3.1 of the XML recommendation says: "Note that the order of attribute specifications in a start-tag or empty-element tag is not significant.").
这篇关于如何使用XmlSerializer指定XmlAttributes的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!