all groups > dotnet remoting > july 2006 >
You're in the

dotnet remoting

group:

Serializing XmlDocument to SerializationInfo


Serializing XmlDocument to SerializationInfo scarleton NO[at]SPAM gmail.com
7/31/2006 3:26:22 PM
dotnet remoting:
I need to store a XmlDocument within another object that is being
serialized. The other object does implement the ISerializable
interface. The problem is that the XmlDocument, when saved as a text
file, can be many megs in size. What is the best way to serialize the
XmlDocument to the SerializationInfo object?

Sam
Re: Serializing XmlDocument to SerializationInfo Dave Sexton
8/2/2006 12:13:01 AM
Hi Sam,

That depends on the reason why you are serializing the TextDocument and its containing object in the first place. Your could save
the TextDocument to a file, possibly on a web server, and serialize a path string. During deserialization locate the file (and
download it if necessary), then reload it into a TextDocument. You might have to download the document asynchronously, so the
client should be aware of any possible caveats.

--
Dave Sexton

[quoted text, click to view]

Re: Serializing XmlDocument to SerializationInfo Dave Sexton
8/2/2006 1:04:09 AM
Hi Sam,

That depends on the reason why you are serializing the XmlDocument and its containing object in the first place. Your could save
the XmlDocument to a file, possibly on a web server, and serialize a path string. During deserialization locate the file (and
download it if necessary), then reload it into a XmlDocument. You might have to download the document asynchronously, so the
client should be aware of any possible caveats.

--
Dave Sexton

[quoted text, click to view]

Re: Serializing XmlDocument to SerializationInfo scarleton NO[at]SPAM gmail.com
8/3/2006 7:48:14 AM
[quoted text, click to view]

Dave,

Thank you for your reply!

I have two types of serialization going on. One is to a file and the
other is across the wire. The application I am working on is a
client/server app where currently both are on the same physical
machine, in version 2, they can be on separate machines, but all in the
same local area network. There is no plain to ever make this system
work over the Internet or use any web server type of things.

The XML is created in an XmlDocument object that is the raw data for a
report. The XmlDocument object is being added to a C# business class
call "ReportDocument" which contains additional information. It is
within this Report class that I need to figure out how to serialize the
XmlDocument.

The code that writes a ReportDocument to file is generic, right now at
least, to how all documents within the system are written to file and
they all depend on the object implementing the ISerializable interface.
I am using standard remoting to send objects across the wire, right
now, too. So both remoting and writing to file is using ISerializable.

After some testing, it looks like if the text within the XML is
compressed, I can get the size down to under half a meg of data, so I
would be comfortable with serializing that size of binary blob. In the
short term, I think this is the best approach. Is there a better one?

Assuming my approach, I figure I can stream the XmlDocument to a memory
stream and then compress the memory stream, but I am back at how best
to stream this compresed blob into the SerializationInfo. Any
thoughts?

Sam
Re: Serializing XmlDocument to SerializationInfo Dave Sexton
8/3/2006 12:17:41 PM
Hi Sam,

Are you worried about the size of data being transmitted to/from a remoting client?

Prior to version 2 you can use an IPCChannel which alleviates the requirement for sockets since it uses local pipes only.

If you are using binary serialization over Tcp that will help to decrease the size of messages transmitted to/from a remoting
client. Your compression idea sounds like it will help as well. As you mentioned you can serialize the XmlDocument into a
MemoryStream and compress the stream. Just add the stream reference to the SerializationInfo with a custom key like, "doc_bits".
Stream is serializable (as is MemoryStream, of course). In your deserialization constructor just pull the stream from the
SerializationInfo, decompress and deserialize back into an XmlDocument.

--
Dave Sexton

[quoted text, click to view]

Re: Serializing XmlDocument to SerializationInfo scarleton NO[at]SPAM gmail.com
8/4/2006 6:21:54 AM

[quoted text, click to view]

Brain fart on my part, I was looking for MemoryStream and Stream to
implement the ISerializable interface, I missed the fact that they have
[SerializableAttribute]. Dumb-de-dumb-de-dumb ;) thanks!

Sam
AddThis Social Bookmark Button