Deep XML Serialization revisited

J

Jesper Denmark

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("first")]
public string FirstName;
[XmlElement("last")]
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.
 
D

Dennis Doomen

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

(e-mail address removed)
 
K

Kieran Benton

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top