473,320 Members | 1,933 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.

Why would I want to serialise something

I read a lot about serialising things to XML. Can someone give me some
examples of why I would want to do this? I seem to be missing the point.
Jul 22 '05 #1
4 1515
CT
You might not have to do any serialization in your applications, but if you
think passing information over the Internet and say througha firwall that
doesn't allow binary objects to be passes, then you can possibly serailize
to XML, which is text only, and this will (hopefully ;-)) pass thropugh the
firewall and it can be desrialized at the other end. That's one good use of
serialization.

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities - http://community.integratedsolutions.dk

"Graham Like" <Gr********@discussions.microsoft.com> wrote in message
news:D7**********************************@microsof t.com...
I read a lot about serialising things to XML. Can someone give me some
examples of why I would want to do this? I seem to be missing the point.

Jul 22 '05 #2
Hi Graham,
I read a lot about serialising things to XML. Can someone give me some
examples of why I would want to do this? I seem to be missing the point.


Serialization is a very helpful mechanism.

Traditionally, we create applications that either collect, analyze, or
transfer information. For some data collection systems, relational
databases are a terrific answer. The fields in each transaction are the
same and the existence of a value doesn't often drive the need for a
completely different data structure. Data can and should be collected in
rows and columns and stored in a relational database.

Problem is that databases are a bit too good. They are adaptable and
versatile, and we've been taught to use them for every data persistence
opportunity. "If all you have is a hammer, everything looks like a nail".

Some kinds and uses of data persistence are not well suited for pure
relational databases. What kinds are there? Look for the stuff that
"smells funny." Large data blocks stored as a blob in a database (not
including image files). Situations where a single key may refer to any of a
dozen tables (as a primary key) but never more than one. Situations where a
database table is created to have a set of fields of different types and an
indicator to tell the programmer which field contains the value, as a way of
allowing data of different types to be stored. Situations where database
records are created with an "OptionalField1", "OptionalField2" and
"OptionalField3" in their definition, to allow the user to define the
meanings of the fields (but you'd better not exceed three, or else!).

All these situations are ones that I see daily. They are all limitations of
the relational paradigm (and, in fact, the purely heirarchical database does
no better). The interesting thing is that if your data is Object Oriented,
the OO side of your app has little or no difficulty dealing with things like
this. The problem is not representing the data. The problem is persisting
it.

Applications that have to cope with data that "doesn't follow the rules" are
common. These applications become complex, especially in the data
persistence layer. Engineers have termed this to be "Object Relational
Impedence". In other words, you have to write a LOT of code to get over the
fact that your objects cannot be easily converted to a relational database
format.

Serialization can be used as a way of persisting the data without storing it
to a relational database. You get none of the transactional features of a
relational database. However, in some cases, you don't need it. In those
cases, you can make your code considerably simpler by using serialization to
persist the data than you would be able to if you were writing to a
relational database.

In other cases, you can combine the two, where you store some data in
relational tables, but then you leave in an XML column where you serialize
the entire object or some fragment of it, where the fragment is the portion
of your data that doesn't "follow the rules". In SQL Server 2000, you had
to create a 'text' field to hold this data, but in the newest SQL Server
(Yukon), you can define the field to be of type 'XML' and not only store XML
data in it, but query the data in those fields using XPath queries, and
enforce constraints on the data.

In other situations, like those involved in transmitting information between
systems (B-to-B or systems integration), a database is more of a problem
than a solution. In situations like this, you need to be able to take a
"snapshot" of a transaction in time, completely wrap it up (potentially sign
it), and send just one transaction, with all associated data, from one place
to another. In this case, an object can be composed in memory, serialized
to a single string, and transmitted as a self-contained business transaction
through a reliable messaging mechanism. This is a fundamental notion in
Service Oriented Architecture, or SOA.

The ability to serialize and deserialize is something that has to be
hand-coded when it cannot be provided by the tools. I've seen countless
situations where buckets of code can be replaced with three calls to the
framework for serialization and deserialization. I cannot say enough how
important this is for reducing the complexity of the code and therefore,
reducing the cost to create, test, and maintain.

Hope this helps,
--- Nick

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Jul 22 '05 #3
Another use for serialization that I have seen is for configuration
files.

Suppose you have a Config class that looks like this:

Public Class Config
Public FilePath As String
Public Server As String
Public MaxLoginAttempts As Integer
End Class

In your code, you can have an instance of this class to handle your
configuration information and it makes the code readable but you may
wish to serialize the object instance to disk to save it.

Just an example

Jul 22 '05 #4
Hi there,

You want to serialize things mainly for transport and state persistance. For
example, if you have an object with property Color, and you assign a color,
then serialize it and save it somewhere, then when you deserialize it your
object's property will still have a color value assigned. In other words it
allows you to save an image of an object at a particular point in time.
Another use is if you have an object that you need to pass on say from server
to server (Remoting). You can serialize it and send it via TCP and
deserialize it on the other side. The resulting object will have all the
properties from the one on the other server.

XML is another way of serializing objects that simply creates an XML
document out of them. The benefit (and problem) is that you can read the
contents of the object with a text editor, while binary (obviously) produces
a dump of crap that you could not possibly understand : )

I hope that helps.

Good luck!

--
Juan Romero
-----------------------------------------
The successful person has the habit of doing the things failures don't like
to do.
E.M. Gray
"Graham Like" wrote:
I read a lot about serialising things to XML. Can someone give me some
examples of why I would want to do this? I seem to be missing the point.

Jul 22 '05 #5

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

Similar topics

2
by: SL_McManus | last post by:
Hi All; I am fairly new to Perl. I have a file with close to 3000 lines that I would like to split out in a certain way. I would like to put the record type starting in column 1 for 2 spaces,...
182
by: Jim Hubbard | last post by:
http://www.eweek.com/article2/0,1759,1774642,00.asp
4
by: Graham Like | last post by:
I read a lot about serialising things to XML. Can someone give me some examples of why I would want to do this? I seem to be missing the point.
1
by: Steve | last post by:
I am reworking a class that generates source code. I want to add a "preview" function, much like the refactor dialog in vs2005. To facilitate this, I have changed what used to be my "writeToFile"...
2
by: Glenn | last post by:
Hi Here's the scenario... I have a web method to which a pass a customer ID. The web method looks up the customer and returns an XmlNode which I deserialise into a type. I then update...
6
by: mangesh | last post by:
How to serialise objects in c++ , in java one has to implement serilisable interface . Regards mangesh.
3
by: Phill W. | last post by:
OK, I've asked nicely before; now I'm going to throw down the gauntlet to anyone brave enough to take it up. In VB'2005, can anyone write me a class that inherits from System.Data.DataTable, add...
6
by: Frank Hauptlorenz | last post by:
Hello, I'm trying to send an SqlCommand to a WCF-Service. For this I'm using the following DataContract: public class SqlCommandComposite { SqlCommand cmd = new SqlCommand();
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.