Hi,
I want to deserialize an xml file which has to be just in this form
<Basket>
<Fruit>Apple</Fruit>
<Fruit>Orange</Fruit>
<Fruit>Grapes</Fruit>
</Basket>
Out of the examples I read on internet the least possible format I could find was the following
<Basket>
<FruitArray>
<Fruit>Apple</Fruit>
</FruitArray>
<FruitArray>
<Fruit>Orange</Fruit>
</FruitArray>
<FruitArray>
<Fruit>Grapes</Fruit>
</FruitArray>
</Basket>
and that has the following deserialization class for converting it into a class object.
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
{
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("FruitArray")]
public FruitArray[] objFruitArray;
}
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "BasketNamespace")]
public class FruitArray
{
/// <remarks/>
private string _Fruit;
public string Fruit
{
get { return _Fruit; }
set { _Fruit = value; }
}
}
}
Can I add something like the following directly under top class
private string _Fruit;
public string Fruit
{
get { return _Fruit; }
set { _Fruit = value; }
}
and avoid the array nesting?
my goal is to deserialize an xml of following format
<Basket>
<Fruit>Apple</Fruit>
<Fruit>Orange</Fruit>
<Fruit>Grapes</Fruit>
</Basket>