how can I save binary data in XML?

How can I insert binary data(such as pictures or programs) in XML document
Is it even possible(CDATA maybe)
and if there is a way can you give a simple example
thanks in advance.


Answer this question

how can I save binary data in XML?

  • Mr. Poll

    You can encode it to base64 string, then place it in the XML like any other string:

    byte
    [] binaryData = new byte[fileStream.Length];

    string xmlData;

    fileStream.Read (binaryData,0,(int)fileStream.Length);

    fileStream.Close ();

    xmlData = System.Convert.ToBase64String (binaryData,0,binaryData.Length );

    ... (place xmlData in the XML)


  • how can I save binary data in XML?