binary vs. xml serialization

A

Alex D.

does any body knows the pros and cons between binary and xml serialization
if use it to persist objects in a database and which one is the best option?
Tnx.
 
K

Karl Seguin

Binary is faster and will serialize all members (read-only and everything)

XML is more interoperable and human readable.

If you are the only consumer of the serialized data, i'm consider binary,
else i'd consider XML to make it easier for others.

Karl
 
A

Alex D.

I agree with you, also I have a viewer-editor for my ojects already so I
just need to deserialize and pass to the viewer-editor. so I think binary is
the way to go for me.
Thanks!
 
K

Kevin Spencer

Another consideration is extensibility. For example, we have developed some
services that run constantly, and maintain logs. These logs are files that
contain various status data. Originally, we were required to be able to send
reports from these logs to various people connected with the project.
Initially, I wrote a class that parses these logs and builds strings for
emails containing the reports.

Then we received a requirement that there should be a web site where
up-to-the-minute reports could be seen. I suddenly realized that I had not
planned for this. So, I built serializable log classes that contain the
status data necessary to do any type of reporting. These classes are
instantiated by the service when it runs, and data is stored in them until
each job finishes. At that point, the classes are serialized into log files
(as XML). The ASP.Net web page can then open these files, and use an XSL
Tranform to convert the data to nicely-formatted HTML. The formatting is
removed from the classes, and if we want to change the look of the reports,
it can all be done by modifying the XSL document and the CSS style sheet
used. In the future, if we need these reports formatted any other way, we
can just write XSLTs to do the formatting. And each class has a ToString()
overload to provide the "plain text" version for emails, or can use an XSLT
to do HTML-formatted emails.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
A

Alex D.

thats a great solution there! In my case my objects are almost pure logic so
I do not have much data to show in them, the interesting part is inside
functions hence requiring being deserialized first. also as my objects are
going to persist for long time in SQL then binary format might help with the
database size.
I your case it seem to be the best approach the use of XML.
Thanks for sharing your story with us.

Regards, Alex
 

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

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top