none
Ensure XElements order RRS feed

  • Question

  • Hello. Suppose we have some XElements which are items of other  XElement. How can we ensure the same order of elements in the xml file. Is it guaranteed or not?
    Wednesday, March 29, 2017 8:25 AM

All replies

  • >>How can we ensure the same order of elements in the xml file

    I suggest you try XmlElementAttribute.Order Property.

    [XmlRoot("Object")
    public class SerializableObjectForPersistance
    {
        [XmlElement(Order = 1)]
        public bool Property1 { get; set; }
        [XmlElement(Order = 3)]
        public bool Property3 { get; set; }
        [XmlElement(Order = 2, IsNullable=true)]
        public bool Property2 { get; set; }
    }
    

    If it did not work for you, it would be helpful if you could share us detailed steps to reproduce your issue.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 30, 2017 2:50 AM