Can I save Byte[] in a XML file?

  • Thread starter Thread starter shapper
  • Start date Start date
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
 
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
 
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.
 
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.
 
Back
Top