Any way to make XmlSerializer output xml in a defined order?

后端 未结 3 1342
自闭症患者
自闭症患者 2020-12-19 07:44

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 comp

相关标签:
3条回答
  • 2020-12-19 07:54

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

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

    0 讨论(0)
  • 2020-12-19 08:03

    Decorate your properties with the XmlElementAttribute, setting the Order parameter.

    0 讨论(0)
  • 2020-12-19 08:13

    ps: I don't believe the XML generated by the XmlSerializer is in an undefined order. It may be undocumented, but it is known. I believe that in the absence of Order attributes, the XmlSerializer serializes all public Properties, alpha-sorted by prop name, and then all public Fields, alpha-sorted by name.

    0 讨论(0)
提交回复
热议问题