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

Is using XmlSerializer the right choice?

Hi all

I'm learning XML and .NET and I saw an example of using XmlSerializer to
deserialize an XML file to get the corresponding object in memory. I found
it very useful for my purpose. However, for simple properties it works for
me, but I actually need a bit more than just properties.

For example, my class actually contains a collection of strings as well, now
is using XmlSerializer the right choice? I don't know how many there will
be, but ideally I can just create a file (say an XML) and add as many strings
as necessary such that they will be added to the collection of the object in
memory.

Any pointers or suggestions are greatly appreciated! Thanks!

Nov 12 '05 #1
2 1544
Hi,

You can decide if you would use the XmlSerializer or not based on how you
want to design your classes; because XmlSerializer imposes certain
restrictions on your classes desings. Mainly, you must have a default
constructor and you must have getters and setters on all properties that you
want to serialize, if that is the way you are building your class, then use
the XmlSerializer, otherwise if you feel unhappy with these restrictions,
then you can go your own way.
<yi*********@newsgroup.nospam> wrote in message
news:4E**********************************@microsof t.com...
Hi all

I'm learning XML and .NET and I saw an example of using XmlSerializer to
deserialize an XML file to get the corresponding object in memory. I
found
it very useful for my purpose. However, for simple properties it works
for
me, but I actually need a bit more than just properties.

For example, my class actually contains a collection of strings as well,
now
is using XmlSerializer the right choice? I don't know how many there will
be, but ideally I can just create a file (say an XML) and add as many
strings
as necessary such that they will be added to the collection of the object
in
memory.

Any pointers or suggestions are greatly appreciated! Thanks!

Nov 12 '05 #2
Hi,

Based on your description, I think you need to save some data in your class
to xml file.

If you need to save the whole class, and then get the data back to the
class object, xml serialization is a good choice. You can add a public
collection property to the class and the collection will be serialized.

If you only need to save the string collection, You can also try to save
them directly using an XmlDocument object.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #3

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...
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...
0
by: Robert Love | last post by:
I am trying to save some boolean values from checkboxes using isolated storage. I am able to do strings and integers without a problem but I can't work out how to save boolean values without seeing...
1
by: Yewen Tang | last post by:
I have a schema file datamodel.xsd, element "properties" is declared as a type of "baseProperty". The schema file also defines "derivedProperty" is a derived type of "baseProperty". <?xml...
0
by: groovyghoul | last post by:
Hi I have the following XML file: =========================================================== <?xml version="1.0" encoding="UTF-16"?> <Policy xmlns="http://tempuri.org/richard.xsd"> <TransType...
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...
1
by: kimtherkelsen | last post by:
Hi, I want to send XML data from a server to some clients over a network connection using the TCP/IP protocol. If I send the XMLs as byte arrays I need to insert header information in the data to...
2
by: =?Utf-8?B?U2hhd24=?= | last post by:
Hi; I would like to be able to use the XMLSerializer to serialize and deserialize a dictionary. is that possible? i know that you can serialize an object that implements the ICollection interface....
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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?
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
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
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...

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.