473,403 Members | 2,293 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,403 software developers and data experts.

XML Serialization, collection with parental links

Hi there,

I'm writing a custom collection, which will be referened within a
class. Each item within the collection needs to have a link to the
parent container class, e.g.

Item x;
Container c = x.ParentContainer;

I basically got the idea from ControlCollection class, where each
control has a reference to its parent control.
So far, I've implemented it as follows.

class Container
{
public ItemCollection Items { get; }
}

class ItemCollection
{
public ItemCollection(Container container) { .. }
public void Add(Item item) { _innerCollection.Add(item);
item.SetContainer(_container); }
}

class Item
{
// gets the reference to the parent container
public Container ParentContainer { get; }
}

I need to be able to serialize the Container class and all its members
into XML, and then deserialize it. Upon deserialization, I'm able to
get the values back into the collection. However, the links to the
parent container are not preserved.
I've read that .NET XML serializer doesn't work with circular
references. Perhaps this could be the reason.

Is there a better implementation?
If not, is there a way to relink the parent elements manually upon
deserialization?

Thanks,
-Oleg.

Jul 30 '06 #1
3 1118
i don't how to relink the parent elements upon deserailization. but i
think after deserailzation process , you can manually use this to
relink relation.

Class Continer
{
public void Relink()
{
foreach (Item item in this.Items)
{
item.SetContainer(this);
}
}
}

Sincerely,
simida

Ol*********@gmail.com 写道:
Hi there,

I'm writing a custom collection, which will be referened within a
class. Each item within the collection needs to have a link to the
parent container class, e.g.

Item x;
Container c = x.ParentContainer;

I basically got the idea from ControlCollection class, where each
control has a reference to its parent control.
So far, I've implemented it as follows.

class Container
{
public ItemCollection Items { get; }
}

class ItemCollection
{
public ItemCollection(Container container) { .. }
public void Add(Item item) { _innerCollection.Add(item);
item.SetContainer(_container); }
}

class Item
{
// gets the reference to the parent container
public Container ParentContainer { get; }
}

I need to be able to serialize the Container class and all its members
into XML, and then deserialize it. Upon deserialization, I'm able to
get the values back into the collection. However, the links to the
parent container are not preserved.
I've read that .NET XML serializer doesn't work with circular
references. Perhaps this could be the reason.

Is there a better implementation?
If not, is there a way to relink the parent elements manually upon
deserialization?

Thanks,
-Oleg.
Jul 31 '06 #2
Is there a better implementation?
If not, is there a way to relink the parent elements manually upon
deserialization?
Sure, just wire them back up after deserialization, using the parent.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Magician

A man, a plan, a canal.
a palindrome that has gone to s**t.
<Ol*********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi there,

I'm writing a custom collection, which will be referened within a
class. Each item within the collection needs to have a link to the
parent container class, e.g.

Item x;
Container c = x.ParentContainer;

I basically got the idea from ControlCollection class, where each
control has a reference to its parent control.
So far, I've implemented it as follows.

class Container
{
public ItemCollection Items { get; }
}

class ItemCollection
{
public ItemCollection(Container container) { .. }
public void Add(Item item) { _innerCollection.Add(item);
item.SetContainer(_container); }
}

class Item
{
// gets the reference to the parent container
public Container ParentContainer { get; }
}

I need to be able to serialize the Container class and all its members
into XML, and then deserialize it. Upon deserialization, I'm able to
get the values back into the collection. However, the links to the
parent container are not preserved.
I've read that .NET XML serializer doesn't work with circular
references. Perhaps this could be the reason.

Is there a better implementation?
If not, is there a way to relink the parent elements manually upon
deserialization?

Thanks,
-Oleg.

Jul 31 '06 #3
Yes, that is what I was recommending as well.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Magician

A man, a plan, a canal.
a palindrome that has gone to s**t.
"simida" <yo**********@gmail.comwrote in message
news:11*********************@s13g2000cwa.googlegro ups.com...
i don't how to relink the parent elements upon deserailization. but i
think after deserailzation process , you can manually use this to
relink relation.

Class Continer
{
public void Relink()
{
foreach (Item item in this.Items)
{
item.SetContainer(this);
}
}
}

Sincerely,
simida

Ol*********@gmail.com ??:
Hi there,

I'm writing a custom collection, which will be referened within a
class. Each item within the collection needs to have a link to the
parent container class, e.g.

Item x;
Container c = x.ParentContainer;

I basically got the idea from ControlCollection class, where each
control has a reference to its parent control.
So far, I've implemented it as follows.

class Container
{
public ItemCollection Items { get; }
}

class ItemCollection
{
public ItemCollection(Container container) { .. }
public void Add(Item item) { _innerCollection.Add(item);
item.SetContainer(_container); }
}

class Item
{
// gets the reference to the parent container
public Container ParentContainer { get; }
}

I need to be able to serialize the Container class and all its members
into XML, and then deserialize it. Upon deserialization, I'm able to
get the values back into the collection. However, the links to the
parent container are not preserved.
I've read that .NET XML serializer doesn't work with circular
references. Perhaps this could be the reason.

Is there a better implementation?
If not, is there a way to relink the parent elements manually upon
deserialization?

Thanks,
-Oleg.

Jul 31 '06 #4

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

Similar topics

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...
0
by: Joe Rizla | last post by:
I am using XML Serialization to output the IBuySpy tabs data. I have used System.Xml.Serialization to serialize an array of a class called TabStripDetails. Using attributes I rename the resultant...
2
by: Snowman | last post by:
Suppose I have a RootObject which holds a collection of other objects. The other objects have a property (Parent) which refers back to the "parent" collection (b.t.w. my collection is based on...
4
by: hs | last post by:
Hi I am serializing a dataset using a binary formatter as follows: IFormatter formater = new BinaryFormatter(); formatter.Serialize(stream, ds); // ds=DataSet, stream=MemoryStream .... DataSet...
27
by: Codemonkey | last post by:
Heya All, Sorry, but I think it's about time for a monkey-ramble. I've just had enough of trying to serialize even simple objects with VB. A simple task you may think - stick the...
10
by: SStory | last post by:
My app is near completed for the basic feature of version 1.0. I have an extensive object model and I now want to persist my objects using serialization. I have chosen binaryformatter to...
3
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...
3
by: Oleg.Ogurok | last post by:
Hi there, I'm writing a custom collection, which will be referened within a class. Each item within the collection needs to have a link to the parent container class, e.g. Item x; Container...
2
by: Peter Duniho | last post by:
I've been learning about mechanisms .NET offers to export data. The initial goal is to see what sorts of ways are available to save an application's state (document, internal database, whatever). ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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
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 projectplanning, coding, testing,...
0
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...

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.