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

XmlSerializer for single level serialization of objects ?

Ok the XmlSerializer is nice for my need.

BUT I what I need (maybe the XmlSerializer isnt what I need) is to be
able to take the following
objects

A Person who has a collection of Addresses

Person
(fname)
(lname)
Address
(Street)
(City)
(State)
(Zip)

And Serialize the Person object Seperatly from the Addresses.

What is the best way to do this ?

Inverse recursion ?

What I would like in the end are 2 strings, 1 representing the Person
and 1 representing the address.

If there were 2 addresses then 3 strings, 1 for the person, and 1 for
EACH address.

Thanks

Chris

Dec 6 '06 #1
4 1917
Hi Chris,

Could you just mark the address property of the Person object to be ignored
by the serializer (XmlIgnore i think). Serialise the Person to get your
first string, then iterate over the addresses and serialize them one by one?

ta,
Andrew

<cw******@gmail.comwrote in message
news:11**********************@16g2000cwy.googlegro ups.com...
Ok the XmlSerializer is nice for my need.

BUT I what I need (maybe the XmlSerializer isnt what I need) is to be
able to take the following
objects

A Person who has a collection of Addresses

Person
(fname)
(lname)
Address
(Street)
(City)
(State)
(Zip)

And Serialize the Person object Seperatly from the Addresses.

What is the best way to do this ?

Inverse recursion ?

What I would like in the end are 2 strings, 1 representing the Person
and 1 representing the address.

If there were 2 addresses then 3 strings, 1 for the person, and 1 for
EACH address.

Thanks

Chris

Dec 6 '06 #2
Hmm....thats a way...not bad.....

What I would really like to do is be able through reflection determine
if a property base type implments IEnumerable.

I have an app that I have several functions I need to determine if a
given propety is a a type of Collection

It could (and in most cases is) a Generic Collection

It could be , and array , an array list , etc though.

How can I determine if its A collection, or enumerable ?

I hate to impose contratints like that on Domain Design that all
collections must be ignored....etc.

BUT its better than what I had so far.

If I could just figure out how to determine if a property implments
IEnum, etc...

Thanks

Chris

Andrew Brook wrote:
Hi Chris,

Could you just mark the address property of the Person object to be ignored
by the serializer (XmlIgnore i think). Serialise the Person to get your
first string, then iterate over the addresses and serialize them one by one?

ta,
Andrew

<cw******@gmail.comwrote in message
news:11**********************@16g2000cwy.googlegro ups.com...
Ok the XmlSerializer is nice for my need.

BUT I what I need (maybe the XmlSerializer isnt what I need) is to be
able to take the following
objects

A Person who has a collection of Addresses

Person
(fname)
(lname)
Address
(Street)
(City)
(State)
(Zip)

And Serialize the Person object Seperatly from the Addresses.

What is the best way to do this ?

Inverse recursion ?

What I would like in the end are 2 strings, 1 representing the Person
and 1 representing the address.

If there were 2 addresses then 3 strings, 1 for the person, and 1 for
EACH address.

Thanks

Chris
Dec 6 '06 #3
System.Diagnostics.Debug.WriteLine("Addresses is " +
(typeof(IEnumerable).IsAssignableFrom(myObject.Get Type().GetProperty("Addresses").PropertyType)
? String.Empty : "not ") + "IEnumerable");

That should determine if your property is IEnumerable, although since
ICollection is derived from IEnumerable, it'd be better to check for
ICollection if you want to exclude them. But this is not behavior you can
dictate to the serializer (unless you can get it to fire the UnknownElement
event)
Dec 6 '06 #4
BINGO !

Thanks a TON !

It was driving me nuts, I was calling TypeOf differently and missing
the IsAssignableFrom

So NOW I can loop through my properties

You are 100% correct about the ICollection (I want thinking of the fact
ICollection is derived from IEnumerable)

What I plan to do as far as the serializer goes is loop from the Bottom
Up setting the collections to nothign after they have been individually
serialized. That Ive got ok, its not clean but it works.
Thanks again......


Keith Patrick wrote:
System.Diagnostics.Debug.WriteLine("Addresses is " +
(typeof(IEnumerable).IsAssignableFrom(myObject.Get Type().GetProperty("Addresses").PropertyType)
? String.Empty : "not ") + "IEnumerable");

That should determine if your property is IEnumerable, although since
ICollection is derived from IEnumerable, it'd be better to check for
ICollection if you want to exclude them. But this is not behavior you can
dictate to the serializer (unless you can get it to fire the UnknownElement
event)
Dec 7 '06 #5

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

Similar topics

5
by: Stuart Robertson | last post by:
I am trying to find a solution that will allow me to use XmlSerializer to serialize/deserialize a collection of objects where a given object is shared between two or more other objects, and not...
8
by: Harris Boyce | last post by:
Hello, I'm trying to use the FOR XML EXPLICIT clause with SQL Server to deserialize data from my database into a strongly-typed collection object that I will use throughout my application. I...
1
by: Bluetears76 | last post by:
Hi I have a hirachy of classes which are Message(base), then FileMessage and ChatMessage (extended) I want to serialize the objects and when i am deserizaling i dont know if i am getting...
3
by: MattB | last post by:
Hello I got this working but it is not how I really want it, basically I have an xml file which has a root of <test> and can be filled with 3 different types of <question> elements with different...
12
by: SJD | last post by:
I've just read Christoph Schittko's article on XmlSerializer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp . . . and very informative it is too....
4
by: Steve Long | last post by:
Hello, I hope this is the right group to post this to. I'm trying to serialize a class I've written and I'd like to be able to serialze to both binary and xml formats. Binary serialization is...
10
by: Henrik Dahl | last post by:
Hello! I have an xml schema which has a date typed attribute. I have used xsd.exe to create a class library for XmlSerializer. The result of XmlSerializer.Serialize(...) should be passed as the...
9
by: =?Utf-8?B?ai5hLiBoYXJyaW1hbg==?= | last post by:
Hi, I have a schema that has an optional element, fieldTag4000Field. If the element is omitted from the XML request, when it is deserialized, it will be null when I check it - which is fine. ...
5
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, I am using XML serialization for the first time and I have noticed something unexpected. The object I am serializing contains a field private NumericSettings _numericSettings; public...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.