none
[Serializable] some questions, for a list RRS feed

  • Question

  • Hello,
    My target is that to write a xml file.
    <Root operator="ID4523">
      <Job assembly="IAss44" assemblyRev="1.6" name="LM0001-21" >
        <Barcode time="2019-01-28T16:57:31+01:00" id="124Rev01472">
          <ImageBarcode scanTime="2019-01-28T16:57:31+01:00" id="124z114" />
          <ImageBarcode scanTime="2019-01-28T16:57:31+01:00" id="124z115" />
    With the list I'm not sure.
    I no longer need the keyword [Serializable] under VS2017, is that correct?
    [XmlType]
    Is there an overview of which keywords do what exactly?
    My code, works, but I want to know is right.
    //  [Serializable]
    public class Barcode
    {
    	// ATTRIBUTES
    	[XmlAttribute("time")]
    	public string ScanTime { get; set; }
    
    	[XmlAttribute("id")]
    	public string Id { get; set; }
    
    	// ELEMENTS
    	[XmlElement("ImageBarcode")]
    	//[XmlArray("ImageBarcode")]
    	//[XmlArrayItem("test")]
    	//[XmlIgnore]
    	public List<ImageBarcode> ListImageBarcode { get; set; }
    
    	public void Append(string scanTime, string id)
    	{
    		ListImageBarcode.Add(new ImageBarcode(scanTime, id));
    	}

    With best regards Markus



    Monday, January 28, 2019 6:11 PM

Answers

  • Hi Markus Freitag,

    For XML Serialization, we could use XmlElement, XmlArray, XmlArrayItem, XmlRoot, XmlType to control it. for more information, please refer to:

    Controlling XML Serialization Using Attributes

    Best regards,

    Zhanglong


    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.

    • Marked as answer by Markus Freitag Tuesday, January 29, 2019 5:21 PM
    Tuesday, January 29, 2019 3:03 AM
    Moderator