Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can <a href="http://msdn.microsoft.com/en-us/library/2baksw0z%28v=vs.71%29.aspx" rel="nofollow">control xml serialization using attributes</a>. Use <a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlattributeattribute.aspx" rel="nofollow"><code>XmlAttribute</code></a> attribute, to change default serialization as element to serialization as attribute. Use <a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlelementattribute.aspx" rel="nofollow"><code>XmlElement</code></a> attribute to serialize lists as a flat sequence of xml elements.</p> <pre><code>public class Product { public Cycle Cycle { get; set; } public Brand Brand { get; set; } public List&lt;Item&gt; Updates { get; set; } } public class Cycle { [XmlAttribute("Type")] public string Type { get; set; } } public class Brand { [XmlAttribute("Type")] public string Type { get; set; } [XmlAttribute("Include")] public string Include { get; set; } } public class Item { [XmlAttribute("Name")] public string Name { get; set; } [XmlElement("Artifact")] public List&lt;Artifact&gt; Artifacts { get; set; } } public class Artifact { [XmlAttribute("Kind")] public int Kind { get; set; } [XmlAttribute("Action")] public int Action { get; set; } } </code></pre> <p>Serialization:</p> <pre><code>Product p = new Product() { Cycle = new Cycle() { Type = "x0446" }, Brand = new Brand() { Type = "z773g", Include = "All" }, Updates = new List&lt;Item&gt;() { new Item() { Name = "Foo", Artifacts = new List&lt;Artifact&gt;() { new Artifact() { Action = 3, Kind = 6 } } }, new Item() { Name = "Bar", Artifacts = new List&lt;Artifact&gt;() { new Artifact() { Action = 3, Kind = 6 }, new Artifact() { Action = 3, Kind = 53 }, } } } }; XmlSerializer serializer = new XmlSerializer(typeof(Product)); Stream stream = new MemoryStream(); // use whatever you need serializer.Serialize(stream, p); </code></pre> <p>Result:</p> <pre><code>&lt;Product&gt; &lt;Cycle Type = "x0446" /&gt; &lt;Brand Type = "z773g" Include="All" /&gt; &lt;Updates&gt; &lt;Item Name = "Foo"&gt; &lt;Artifact Kind="6" Action="3" /&gt; &lt;/Item&gt; &lt;Item Name = "Bar"&gt; &lt;Artifact Kind="6" Action="3" /&gt; &lt;Artifact Kind="53" Action="3" /&gt; &lt;/Item&gt; &lt;/Updates&gt; &lt;/Product&gt; </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. 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.
    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