Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I do this quite often. I usually use a top level class that encapsulates the collection property as a member and has a one to one relationship with the xml file. Members of that class can be collections or simple attributes etc.</p> <p>Here is a code snippet for having a collection of custom objects:</p> <pre><code>[System.SerializableAttribute()] [System.Xml.Serialization.XmlRootAttribute(ElementName = "DeployRuns", Namespace = "", IsNullable = false)] public class DeployRuns : List&lt;RunDetail&gt; { </code></pre> <p>And then if you want to encapsulate your collection inside another class which will be serialized, see the bottom property of this class:</p> <pre><code>[System.SerializableAttribute()] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] public class DeployDetails { public DeployDetails() { this.DeployRuns = new DeployRuns(); } [System.Xml.Serialization.XmlAttributeAttribute("sourcePath")] public string SourcePath { get; set; } [System.Xml.Serialization.XmlAttributeAttribute("archiveDestinationPath")] public string ArchiveDestinationPath { get; set; } [System.Xml.Serialization.XmlAttributeAttribute("databaseDestinationPath")] public string DatabaseDestinationPath { get; set; } public DeployRuns DeployRuns { get; set; } } </code></pre> <p>And to finish off the code example, here is my top level class for this hierarchy:</p> <pre><code>[System.SerializableAttribute()] [System.Xml.Serialization.XmlRootAttribute(ElementName = "ExecutionHistory", Namespace = "", IsNullable = false)] public class ExecutionHistory { public ExecutionHistory() { this.CaptureDetails = new CaptureDetails(); this.DeployDetails = new DeployDetails(); } [XmlElementAttribute("CaptureDetails", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] public CaptureDetails CaptureDetails { get; set; } [XmlElementAttribute("DeployDetails", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] public DeployDetails DeployDetails { get; set; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload