Note that there are some explanatory texts on larger screens.

plurals
  1. POwriting a Simplest XML DeSerialization class for the simplest xml file. How to avoid the nesting? deserialize at root?
    primarykey
    data
    text
    <p>I want to deserialize an xml file which has to be just in this form</p> <pre><code>&lt;Basket&gt; &lt;Fruit&gt;Apple&lt;/Fruit&gt; &lt;Fruit&gt;Orange&lt;/Fruit&gt; &lt;Fruit&gt;Grapes&lt;/Fruit&gt; &lt;/Basket&gt; </code></pre> <p>Out of the examples I read on internet the least possible format I could find was the following</p> <pre><code>&lt;Basket&gt; &lt;FruitArray&gt; &lt;Fruit&gt;Apple&lt;/Fruit&gt; &lt;/FruitArray&gt; &lt;FruitArray&gt; &lt;Fruit&gt;Orange&lt;/Fruit&gt; &lt;/FruitArray&gt; &lt;FruitArray&gt; &lt;Fruit&gt;Grapes&lt;/Fruit&gt; &lt;/FruitArray&gt; &lt;/Basket&gt; </code></pre> <p>and that has the following deserialization class for converting it into a class object.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace XMLSerialization_Basket { [System.Xml.Serialization.XmlRootAttribute("Basket", Namespace = "BasketNamespace", IsNullable = false)] public class Basket { /// &lt;remarks/&gt; [System.Xml.Serialization.XmlElementAttribute("FruitArray")] public FruitArray[] objFruitArray; } /// &lt;remarks/&gt; [System.Xml.Serialization.XmlTypeAttribute(Namespace = "BasketNamespace")] public class FruitArray { /// &lt;remarks/&gt; private string _Fruit; public string Fruit { get { return _Fruit; } set { _Fruit = value; } } } } </code></pre> <p>Can I add something like the following directly under top class</p> <pre><code> private string _Fruit; public string Fruit { get { return _Fruit; } set { _Fruit = value; } } </code></pre> <p>and avoid the array nesting?</p> <p>my goal is to deserialize an xml of following format</p> <pre><code>&lt;Basket&gt; &lt;Fruit&gt;Apple&lt;/Fruit&gt; &lt;Fruit&gt;Orange&lt;/Fruit&gt; &lt;Fruit&gt;Grapes&lt;/Fruit&gt; &lt;/Basket&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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