473,657 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array Serialization

S
Hi there,
Here's a question for ya:
I'm serializing something that looks like this:
[XmlRoot(Element Name="Widget")]
Class Widget --> My base class
[XmlArray(Elemen tName="TextGrou ps")]
[XmlArrayItem(El ementName="Text Group",Type=typ eof(ClassTextGr oup))]
public ArrayList TextGroups --> An arraylist of collections
(TextGroup Collections)
TextGroup --> A custom collection
(collectionbase ) of Text objects
[XmlRoot(Element Name="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 1690
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("MyOrde r1")]
public class Order1
{
[XmlArray(Elemen tName="MyItems" )]
[XmlArrayItem(El ementName="MyIt em",Type=typeof (Item))]
public Item [] ItemsOrders;
}

[XmlRoot("MyOrde r2")]
public class Order2
{
[XmlArray(Elemen tName="MyItems" )]
[XmlArrayItem(El ementName="MyIt em",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
CustomCollectio n class implement the ICollection interface. Here are the
related docs in MSDN:

#Controlling XML Serialization Using Attributes
http://msdn.microsoft.com/library/en...rollingseriali
zationbyxmlseri alizerwithattri butes.asp?frame =true

#http://msdn.microsoft.com/library/en...trollingserial
izationbyxmlser ializerwithattr ibutes.asp?fram e=true
http://msdn.microsoft.com/library/en...ampleofxmlseri
alizationwithxm lserializer.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.m icrosoft.com> wrote in message
news:qM******** *****@cpmsftngx a10.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("MyOrde r1")]
public class Order1
{
[XmlArray(Elemen tName="MyItems" )]
[XmlArrayItem(El ementName="MyIt em",Type=typeof (Item))]
public Item [] ItemsOrders;
}

[XmlRoot("MyOrde r2")]
public class Order2
{
[XmlArray(Elemen tName="MyItems" )]
[XmlArrayItem(El ementName="MyIt em",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
CustomCollectio n class implement the ICollection interface. Here are the
related docs in MSDN:

#Controlling XML Serialization Using Attributes
http://msdn.microsoft.com/library/en...rollingseriali zationbyxmlseri alizerwithattri butes.asp?frame =true

#http://msdn.microsoft.com/library/en...trollingserial izationbyxmlser ializerwithattr ibutes.asp?fram e=true
http://msdn.microsoft.com/library/en...ampleofxmlseri alizationwithxm lserializer.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
1730
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
3073
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 I have to use an array PersonType in the AllPersonalData class. But if I have to implement the "Addition of PersonalType" (i.e. the step 2), I have to use ArrayList instead of a fixed length array. I know that I can use the ArrayList as an...
5
12043
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
4190
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 testing. Here are my two procedures for saving the array and loading it abck in again. Private Sub Save 'create memory stream and formatter Dim msStorage As MemoryStream = New MemoryStream Dim fStorage As IFormatter = New BinaryFormatter
1
3737
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 that accesses a Axis provided web service. The client uses the code generated, using wsdl.exe, from the wsdl file provided by the web service provider. The web response has the following schema (roughly):
0
1332
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
19581
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 having a problem in the calling program. I searched online and found suggestions that I return an Array instead so I modified my code (below) to return an Array instead of an ArrayList. Now I get the message when I try to run just my webservice...
2
3963
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 function returns a double-dimensional array of integers. I ran the wsdl utility and I created a simple .NET web client which calls the function. I noticed that the result is returned as a jagged array, since multi-dimensional arrays cannot be...
6
1994
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 in C#? I was thinking, in so far as in memory, it would be a list of the struct..? For writing to file though, if I do a write of the struct, it's not
5
3788
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);" I thought that it is very hard to memory map structure array. I need both read and write memory mapped file at both side of C# and C++.
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6175
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.