views:

56

answers:

1

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.

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" />

to

<MyType start="joe" end="bob" />

This is just for readability, my own benefit really.

+1  A: 

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.").

Lucero
I take your point. However I have to disagree with that statement you quoted (I know they're not your words), the order is significant to me. Yes it will still work either way, but I do care and I do want to set the order :'(
demoncodemonkey
As an aside, there exists so-called Canonical XML where attributes are sorted lexicographically, see http://www.w3.org/TR/xml-c14n11/#DocumentOrder
0xA3
I see. What you could do is have your own implementation or wrapper for XmlWriter and then sort them as you see fit there.
Lucero