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

Home Posts Topics Members FAQ

XML Serialization of ArrayList causes extra nodes

I'm trying to serialize a class that contains an ArrayList...som ething
like this:

[Serializable]
public class Units
{
private ArrayList _units;
private string _description;

[XmlArray(Elemen tName="units")]
[XmlArrayItem("u nit", typeof(unit))]
public ArrayList units
{
get{ return _units; }
set{ _units = value; }
}
public string description
{
get{ return _description;}
set{ _description = value; }
}
}

What I get when I serialize this is:

<units>
<units>
<description>te st</description>
<unit>
// unit elements go here
</unit>
<unit>
// unit elements go here
</unit>
</units>
</units>

(too many units nodes...one for the class and one for the ArrayList)

What I want is:

<units>
<description>te st</description>
<unit>
// unit elements go here
</unit>
<unit>
// unit elements go here
</unit>
</units>

Apr 28 '06 #1
2 1222
I guess the simple question is:

How do I prevent the ArrayList from spitting out the containing node?

Apr 28 '06 #2
Take a look at XmlElementAttri bute
http://msdn.microsoft.com/library/de...ialization.asp

Your code should be changed to something similar to:
[XmlElement("uni t")]
public ArrayList units {
get { return _units;}
set { _unit = value; }
}

Ion

<df********@gma il.com> wrote in message
news:11******** **************@ i40g2000cwc.goo glegroups.com.. .
I guess the simple question is:

How do I prevent the ArrayList from spitting out the containing node?

May 1 '06 #3

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

Similar topics

3
2224
by: Ice | last post by:
All - I'm pretty comfortable with simple XML serialization of objects. However I observed something the other day and I wanted to know if I solved it the right way. Basically if I have a string which contains a single xml node, I can serialize with this line of code: object = (object)serializer.Deserialize(new
0
1984
by: Casey | last post by:
So I'm using XmlSerializer to serialize out a wrapper object that contains an arbitrary number of other objects. The class definitions listed below are made to be very generic. Some of the objects contain other objects so when I declare my XmlSerializer I need to send along an array of types to be included in the serialization. That works fine until I run into 2 classes with the same name from different asseblies. This causes an XML...
3
5303
by: scoobydoo | last post by:
Hello, I am trying to implement ICloneable's Clone() function, using Serialization. However, my code causes an exception. I have a class derived from TreeNode called "Node1". In Node1, I have implemented Clone() using serialization. When I call the Clone() function, the following exception is thrown at
4
2201
by: Aaron Clamage | last post by:
Hi, Could someone please confirm the following? I think I have found a subtle .NET serialization bug. It occurs when object has a list of items containing another object of the same type and both objects have a non-static member reference to some other static object. In this case, I get an InvalidArgument exception when I try to access the non-static member of the child class. I've included a code sample to clarify. This "bug" is...
2
1801
by: Mike | last post by:
Hello. I am using C# in .NET v1.1. I am trying to serialize an object to disk and read it back again. The serialization seems to work OK (at least, it completes without error). However, I get the following error when trying to deserialize: An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll
1
1583
by: Silesian | last post by:
I realize that this is a newbie question but maybe someone will be able to tell me what am I doing wrong. createFile() gets called each time I have the user generate some numbers which then get added to the binlist ArrayList. I'm able to serialize and deserialize the Arraylist. However, when I deserialize the ArrayList, it will only show the first set of ints. I looked at the bin file and it does get appended to each time. Any help will...
4
2048
by: Stuart | last post by:
I have a small class of data values made up of ints and bools totalling 25 bytes. Each of these 25 byte nodes is stored in another class as an ArrayList with a few more ints. Typically there are around 400 nodes stored in each of these segment classes. - which makes each segment occupy around 10KB. I use further ArrayList to store around 30,000 of these segments, which are read in from a file. If a read in a file that contains 10,000...
4
6776
by: martin.skarsaune | last post by:
We have some SOAP compatilibility issues with Visual Studio .NET. Procedure: 1. Add web reference by importing WSDL from an external system 2. Generate C# classes 3. Try to invoke the remote service Problem 1: Wrapping in arrays If the WSDL file includes a repeating element: <xsd:element name="blabla" maxOccurs="unbounded">
3
6688
by: GreyAlien007 | last post by:
I extended the class TreeNode to add some properties of my liking. Anyway, no problems there, I can add my derived TreeNode into TreeNodeCollections and use the properties etc. However, when I serialize a class containing my new TreeNode, it doesn't seem to save all the properties back up the inheritance chain. The class that is getting serialized has one member to be serialized, a Dictionary<string, List<IOTreeNode>> where IOTreeNode is...
0
8827
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
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
8605
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...
0
7333
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6167
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
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4158
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
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2731
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.