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

Home Posts Topics Members FAQ

Deep XML Serialization revisited

Hi,
I've had a lot of trouble finding a good tutorial showing
deep serialization in XML in C#. All samples I've found
shows merely serialization of a single class. If I want
to serialize members of a class like the 'data' member of
the Person class when I serialize the person object -
which attributes do I need to use?

[XmlRoot("person ")]
public class Person
{
[XmlElement("fir st")]
public string FirstName;
[XmlElement("las t")]
public string LastName;
[XmlElement("url ")]
public string Url;

//which attributes do I need here
public Data data;
}

//which attributes do I need here
public class Data
{
//which attributes do I need here
public string phone;
}

When browsing the internet I can't find any good
tutorials. All that I find on the subject extends the way
serialization works - There must be some good tutorial
that keeps things simple and shows deep serialization. Do
you know of any?

Best regards Jesper.
Nov 15 '05 #1
2 5552
Hi Jesper,

As far as I know, the Formatter will automatically serialize nested
types for you as nested XML elements.

Dennis Doomen
Sioux T.S.O. Netherlands

de***********@s ioux.nl

Jesper Denmark wrote:
Hi,
I've had a lot of trouble finding a good tutorial showing
deep serialization in XML in C#. All samples I've found
shows merely serialization of a single class. If I want
to serialize members of a class like the 'data' member of
the Person class when I serialize the person object -
which attributes do I need to use?

[XmlRoot("person ")]
public class Person
{
[XmlElement("fir st")]
public string FirstName;
[XmlElement("las t")]
public string LastName;
[XmlElement("url ")]
public string Url;

//which attributes do I need here
public Data data;
}

//which attributes do I need here
public class Data
{
//which attributes do I need here
public string phone;
}

When browsing the internet I can't find any good
tutorials. All that I find on the subject extends the way
serialization works - There must be some good tutorial
that keeps things simple and shows deep serialization. Do
you know of any?

Best regards Jesper.


Nov 15 '05 #2
Jesper,
Dennis is correct, as long as the underlying type is serializable (and
you'll get an exception if it isnt) then it will automatically be
serialized. There is no need to explicitly tell the runtime to serialize it,
only apply [NonSerialized] to members that you dont want to be serialized.

HTH
Kieran

"Jesper Denmark" <je****@hotmail .com> wrote in message
news:37******** *************** *****@phx.gbl.. .
Hi,
I've had a lot of trouble finding a good tutorial showing
deep serialization in XML in C#. All samples I've found
shows merely serialization of a single class. If I want
to serialize members of a class like the 'data' member of
the Person class when I serialize the person object -
which attributes do I need to use?

[XmlRoot("person ")]
public class Person
{
[XmlElement("fir st")]
public string FirstName;
[XmlElement("las t")]
public string LastName;
[XmlElement("url ")]
public string Url;

//which attributes do I need here
public Data data;
}

//which attributes do I need here
public class Data
{
//which attributes do I need here
public string phone;
}

When browsing the internet I can't find any good
tutorials. All that I find on the subject extends the way
serialization works - There must be some good tutorial
that keeps things simple and shows deep serialization. Do
you know of any?

Best regards Jesper.

Nov 15 '05 #3

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

Similar topics

13
2182
by: ahaupt | last post by:
Hi all, I'm implementing the Clone() method through the ICloneable interface and don't quite know how deep I need to go for a deep copy. Example: class A: ICloneable { object _val;
1
2335
by: oDDskOOL | last post by:
I realized today that the Hashtable.Clone only produces a shallow copy... that makes me go mad that M$ doesn't even provide a deep copy ctor for the Hashtable class ! mighty tech ducks might reply "oh but what if the types in hastable don't have copy ctors defined? that could lead to dangerous situations". well, but was it a significant effort to provide a copy ctor / deep clone method to this class for objects that provide the...
4
3032
by: jjkboswell | last post by:
I have an XSD which I have generated a class from using the xsd.exe tool. My XSD contains complex types within it, so that the generated class has member variables which are of types that are also defined in the XSD. I deserialize XML data into instances of that class, and serialize back to XML. So far so good. However, in my code I have the concept of wanting to create new copies of these deserialized objects and modifying some of...
3
8746
by: raylopez99 | last post by:
The "C# Cookbook" (O'Reilly / Jay Hilyard), section 3.26, is on deep cloning versus shallow cloning. The scanned pages of this book are found here: http://www.sendspace.com/file/mjyocg (Word format, 3 pp) My question, coming from a C++ background where deep copying is done, is why in C# you would do either deep or shallow copying as suggested by O'Reilly (using the "ICloneable" inhereited interface), at least for the .NET framework. ...
0
8394
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
8825
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...
0
8732
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...
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
7327
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...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.