473,326 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Array Serialization

S
Hi there,
Here's a question for ya:
I'm serializing something that looks like this:
[XmlRoot(ElementName="Widget")]
Class Widget --> My base class
[XmlArray(ElementName="TextGroups")]
[XmlArrayItem(ElementName="TextGroup",Type=typeof(C lassTextGroup))]
public ArrayList TextGroups --> An arraylist of collections
(TextGroup Collections)
TextGroup --> A custom collection
(collectionbase) of Text objects
[XmlRoot(ElementName="Text")]
Text --> The text object

Problem is, the xml comes out like this:
<Widget>
<TextGroups>
<ArrayofText>
<Text>

I would have thought my XmlArrayItem attribute on the ArrayList would have
taken care of this "Arrayof..." business, but is it running into a problem
because it's an array of, essentially, arrays? Any ideas on how I could fix
this without changing the structure of my class??

Thanks,
S
Nov 18 '05 #1
3 1671
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

Nov 18 '05 #2
Hi Stephen,

Have you had a chance to check out the suggestions in my last reply or have
you got any further ideas on this issue? If you have anything unclear or if
there're anything else we can help, please feel free to post here. 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

Nov 18 '05 #3
S
Thanks for the reply Steven.

I think I'm okay.. I changed the structure to where it would work..
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:qM*************@cpmsftngxa10.phx.gbl...
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

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Buddy Ackerman | last post by:
I created a simple class: Public Class MyTestClass Public Test() As String End Class I tried to assign some values to the array Test() and display them like this:
3
by: Franz | last post by:
Let me describe the flow of my program first. 1. Deserialize data from xml file. 2. Addition of "PersonType" class to the AllPersonalData. 3. Serialize data back to the xml file. My question is...
5
by: Abraham Lopez | last post by:
Hi.. Is there a way to convert a System.Array to XML... If you know thanks very much... if you don't... Please do not respond stupid things like " Yes -- many ways."
1
by: elziko | last post by:
My intention is to store an array of singles inside a DataTable so that it can me peristed somehow, maybe XML file, maybe Access/SQL Server I don't know yet so I'm just saving it as an XML file for...
1
by: parrot toes | last post by:
I tried to post this question before, but there was an error when posting. I case it did get posted and in order to avoid duplication, I'll just repost a summary. I have written a dotnet client...
0
by: Mrozik | last post by:
after parsing WSDL definition of java WebService, C# proxy class contains data strutures (I'm using RPC\encoded): public class DateString { /// <remarks/> public string value; }
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
2
by: tiberiu.motoc | last post by:
Hi. I've asked this question on the MSDN forums, but I've had no replies. I'm really stuck, so I'm gonna try my luck here. I have a Java web service which contains a simple function; the...
6
by: Glenn | last post by:
OK, need help in translating what I'd like to do in old school C to best method C# If I was wanting to create an array of struct's, writing and reading them to/from a file.. how would I do this...
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.