none
XML serialization - Attributes - The sequence of attributes RRS feed

  • Question


  • Hello,
    I use the XML serialization. So far well, files are being written.
    How can I sort the attributes, order of listing. From what does it depend?
    IsBe
    <Sides>
      <Side referencePos="0" referenceState="ProcessedNot" no="Side1" isExcecuted="NoState">
    	<BOARDS>
    	  <BOARD index="001" isReference="false" timeEnd="-">
    		<POSITIONS>
    
    MustBe
    <Sides>
      <Side no="Side1" written="xcvfrwwqw" referenceState="ProcessedNot"  isExcecuted="NoState">
    	<BOARDS>
    	  <BOARD index="001" isReference="false" timeEnd="-">
    		<POSITIONS>
    public class Side
    {
    	[XmlAttribute("no")]
    	public Side No { get; set; }
    
    	[XmlAttribute("written")]
    	public string PanelCodeWritten { get; set; }
    
    	[XmlAttribute("referenceState")]
    	public StatePosition ReferenceState;
    
    	[XmlAttribute("isExcecuted")]
    	public Executed IsExcecuted { get; set; }
    Thanks in advance for your answers.
    Greetings Markus


    Wednesday, November 6, 2019 5:40 PM

Answers

  • You can't control that, and you don't need to.  The order of XML attribute is, by definition, not important.  Those two XML files will both work equally well.

    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    • Marked as answer by Markus Freitag Thursday, November 7, 2019 7:14 AM
    Wednesday, November 6, 2019 9:10 PM