Hello everyone,
I am using the Configuration Application block to write an XML
configuration file for my application. Most of it is working fine but I
have a problem serialising some nested structs that have arraylist
fields. What I want to do is to have a ShoppingBasket that will hold
any number of Itemstructs and an AllShoppingBaskets that will hold all
the ShoppingBaskets. The resulting XML I am after should look like
this.
<AllShoppingBaskets>
<ShoppingBasket>
<Item>
<ItemType>ItemType</ItemType>
<ItemCaption>ItemCaption</ItemCaption>
</Item>
</ShoppingBasket >
</AllShoppingBaskets >
To do this I created
- an Item struct:
public struct Item
{
public Item(string itemType, string itemCaption)...
}
- a ShoppingBasket struct:
public struct ShoppingBasket
{
public ShoppingBasket (ArrayList items)...
}
the items Arraylist will hold all the items of the basket.
- and an AllShopingBasket struct.
public struct Stations
{
public Stations (ArrayList allBaskets)...
}
the allBaskets Arraylist will hold all the ShoppingBaskets where every
basket will hold Items.
to serialise the data I am using :
ConfigurationManager.WriteConfiguration("shoppingb asketsettings",
configData);
So in the ConfigData Class I have an AllShopingBaskets property to be
serialized this way I would get
<AllShoppingBaskets>
<AllBaskets>
<anyType xsi:type="ShoppingBasket">
<Items>
<anyType xsi:type="Item">
<ItemType>ItemType</ItemType>
<ItemCaption>ItemCaption</ItemCaption>
</anyType>
</Items>
</anyType>
</AllBaskets>
</AllShoppingBaskets>
But if I have to have an Item and a ShoppingBasket as properties in the
ConfigData class or else I get an XML exception. If I do have those two
I get the above XML but also XML representations of Items and
ShopingBaskets which I don't want. If I use [XMLIgnore] on them it
breaks again.
Any ideas on what I am doing wrong or suggestion on doing this in a
different way?
Cheers