48

How I can store base64 strings in XML?

Do you use CDATA to store base64 strings in XML? Would it help as it allows use of < > within the strings?

Is base64 configurable where you tell it not to use certain chars if they conflict with XML?

Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607

3 Answers3

73

You can just store it as a text or attribute value; no escaping or CDATA sections needed. The standard base 64 characters + and / (other than a-z, A-Z and 0-9) do not interfere with XML parsing at all.

Greg Beech
  • 133,383
  • 43
  • 204
  • 250
22

Base64 only uses alphanumeric characters and '+' (plus), '/' (slash) and '=' (equals). No need to encode anything for XML.

David Schmitt
  • 58,259
  • 26
  • 121
  • 165
13

There are no characters whatsoever in the Base64 charset that will conflict with XML strings.

gkrogers
  • 8,126
  • 3
  • 29
  • 36
Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288