如何使用XmlSerializer指定XmlAttributes的顺序 [英] How to specify the order of XmlAttributes, using XmlSerializer

查看:326
本文介绍了如何使用XmlSerializer指定XmlAttributes的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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屋!

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