Can I save Byte[] in a XML file?

S

shapper

Hello,

Can I save binary data into a XML file?

Basically I need to save a Byte[] to a XML and retrieve it later.

Maybe by converting the Byte[] to Base64 String when saving?
.... and converting it back to Byte[] when retrieving the data?

Thanks,
Miguel
 
P

Peter Duniho

shapper said:
Hello,

Can I save binary data into a XML file?

You can save anything that you can represent as text in an XML file.
Since you can represent binary data as text, you can save it in an XML file.
Basically I need to save a Byte[] to a XML and retrieve it later.

Maybe by converting the Byte[] to Base64 String when saving?
.... and converting it back to Byte[] when retrieving the data?

Yes, Base64 is a fairly common way of encoding binary data so that it
can be saved in an XML file.

Pete
 
S

shapper

shapper said:
Can I save binary data into a XML file?

You can save anything that you can represent as text in an XML file.
Since you can represent binary data as text, you can save it in an XML file.
Basically I need to save a Byte[] to a XML and retrieve it later.
Maybe by converting the Byte[] to Base64 String when saving?
.... and converting it back to Byte[] when retrieving the data?

Yes, Base64 is a fairly common way of encoding binary data so that it
can be saved in an XML file.

Pete

Thank you Pete.
 
B

Bjørn Brox

shapper skrev:
Hello,

Can I save binary data into a XML file?

Basically I need to save a Byte[] to a XML and retrieve it later.

Maybe by converting the Byte[] to Base64 String when saving?
... and converting it back to Byte[] when retrieving the data?

Just use XMlSerialize and you don't have to worry on both saving and
reading the data structures. It takes care of proper encoding both of
binary and other data types.
 

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

Top