473,395 Members | 1,653 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,395 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 1164
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...
7
by: Joe | last post by:
I've tracked the performance issue down to a single class. This class derives from CollectionBase and stores a basic value type such as string, int, double, etc... I also store the type itself...
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...

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.