473,396 Members | 1,923 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,396 software developers and data experts.

Array/NameValue Collection Serialization

Can a name value collection be serialized as attributes to the Xml
element of class containing this name value collection?
For eg.
if a class pControl:

[XmlRoot("Control")]
public class pControl {
.....
NameValueCollection _dynamicProperties;
.....
}

if the _dynamicProperties contains:

Key Value
-------------------------------
name tstControl
readonly true
type button

Can I serialize the class pControl as :
<Root>
....
<control name="tstControl" readonly="true" type="button" />
....
</Root>

Dec 27 '05 #1
1 4010
I developed a workaround for this problem:
[this might be helpful for those who have problems with serializing
NameValueCollection]

For Serializing (MANUAL)
After Serializing the class in an xml file / stream Load the generated
xml using XmlDocument. Then manually added the Attributes to the root
node and write it to the file.

For Deserializing
Add an array of XmlAttribute[] to the class containing the namevalue
collection
when the class is deserialized, those attributes which were not
associated with any property would be added to this array. Write a
function to add element from XmlAttribute array to this name value
collection (filter out any attribute with ":" in it, 'cause there might
be an attribute specifying the type of your object which you might not
want to save in the namevalue collection).

Parag
pa***********@gmail.com wrote:
Can a name value collection be serialized as attributes to the Xml
element of class containing this name value collection?
For eg.
if a class pControl:

[XmlRoot("Control")]
public class pControl {
.....
NameValueCollection _dynamicProperties;
.....
}

if the _dynamicProperties contains:

Key Value
-------------------------------
name tstControl
readonly true
type button

Can I serialize the class pControl as :
<Root>
....
<control name="tstControl" readonly="true" type="button" />
....
</Root>


Jan 6 '06 #2

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

Similar topics

2
by: Nicole - ASP/C# Beginner | last post by:
Hi, I am trying to store a NameValue collection within a ViewState like this: StoreFilterSelection = ViewState; YEt I recieve an error "Cannot implicityly convert type 'system.type' to...
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...
3
by: Daniel Lidström | last post by:
Hello, I want to have a class that contains only a collection of another class. For example: public __gc class Alignment { public: Alignment(); ... };
3
by: S | last post by:
Hi there, Here's a question for ya: I'm serializing something that looks like this: Class Widget --> My base class public ArrayList TextGroups --> An...
6
by: Maziar Aflatoun | last post by:
Hi everyone, Is there a type of array that would do the follow? Store key/value pair Return the current index in the array for a key or value? BTW, I also need to bind it to a dropdown list ....
16
by: Ben Hannon | last post by:
Hi, I'm writting a COM Class in VB.NET to be used in a VB6 project (Tired of the VB6 hassles with cloning and serializing an object). All my classes I need cloneable/serializable are now in a...
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...
4
by: Kyote | last post by:
I'm trying to persist a list of filenames. I've made a custom collection and a FileName class: 'Class to hold file name information Public Class FileNames Public fullName As String Public...
1
by: DesperateDan | last post by:
I've got a parent object that is a collection and it in turn is hosting 2 child objects. My searlization has worked perfectly to plan in as much that I wanted to dictate the names of the objects...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
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...
0
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,...

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.