Hi Stephen,
From your description, you're doing some Xml Serialization work and you
want to serialize a certain class which contains a member and the member is
a Collection of another class's instance. And now you found the serialze
output xml will contain <Arrayof...> which wrap the collection members, and
you want to get rid of it?
Please feel free to let me know, if there is anything I misunderstand.
I'm not very sure about your detailed class code and the actual Xml Output
format you want, would you please provide me a clear class's code list and
also the complete xml output format?
Based on my test locally, here are my findings:
[XmlRoot("MyOrder1")]
public class Order1
{
[XmlArray(ElementName="MyItems")]
[XmlArrayItem(ElementName="MyItem",Type=typeof(Item ))]
public Item [] ItemsOrders;
}
[XmlRoot("MyOrder2")]
public class Order2
{
[XmlArray(ElementName="MyItems")]
[XmlArrayItem(ElementName="MyItem",Type=typeof(Item ))]
public ArrayList ItemsOrders;
}
public class Item
{
public string ItemID;
public string ItemName;
}
The Order1 and Order2 class are all has a member which is the collection of
Item class's instance, one is using a normal Array, and another use
ArrayList, When I serilize them, they out put the following xml:
###for Order1 class:
<?xml version="1.0" encoding="utf-8"?>
<MyOrder1 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MyItems>
<MyItem>
<ItemID>0</ItemID>
<ItemName>Name0</ItemName>
</MyItem>
............................
<MyItem>
<ItemID>4</ItemID>
<ItemName>Name4</ItemName>
</MyItem>
</MyItems>
</MyOrder1>
###for Order2 class:
<?xml version="1.0" encoding="utf-8"?>
<MyOrder2 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MyItems>
<MyItem>
<ItemID>0</ItemID>
<ItemName>Name0</ItemName>
</MyItem>
.................
<MyItem>
<ItemID>4</ItemID>
<ItemName>Name4</ItemName>
</MyItem>
</MyItems>
</MyOrder2>
They both output as the same style, without the "Arrayof..." element. And
from the MSDN code example, the "Arrayof .." will occur when serializing a
CustomCollection class implement the ICollection interface. Here are the
related docs in MSDN:
#Controlling XML Serialization Using Attributes
http://msdn.microsoft.com/library/en...rollingseriali
zationbyxmlserializerwithattributes.asp?frame=true
#
http://msdn.microsoft.com/library/en...trollingserial
izationbyxmlserializerwithattributes.asp?frame=tru e
http://msdn.microsoft.com/library/en...ampleofxmlseri
alizationwithxmlserializer.asp?frame=true
Please feel free to let me know if you have any questions. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx