I need to decode a Base64 string from some XML element. Is there any difference between an element defined by type="xs:base64binary"
and an element defined by type="xs:string"
? Some XSD developers refuse to mark encoded strings as a base64binary. If there is no difference, what is the use of type="xs:base64binary"
?

- 12,959
- 7
- 83
- 96

- 899
- 1
- 13
- 28
3 Answers
There definitely is a difference between base64Binary
and string
in XSD:
- base64Binary represents binary data encoded in Base64. Its value space is the set of fixed length binary octets. Its
lexical space is limited to
a-z
,A-Z
,0-9
,+
,/
,=
, plus whitespace. - string represents character data. Its value space is the set of finite-length sequences of characters. Its lexical space is unconstrained beyond having to consist of XML characters.

- 106,133
- 27
- 181
- 240
If I understand the specs correctly, there is a semantic difference.
A base64Binary
element contains arbitrary, binary data that has been encoded as base64, which makes it basically a string (or at least string-compatible).
On the other hand, strings contain printable characters, which (usually) make up words and sentences (natural language). They cannot contain arbitrary (binary) data, because certain characters aren't allowed.
You can use base64Binary
to indicate that the decoded data is not suitable for human consumption, where as string
is readable/printable.

- 33,626
- 7
- 114
- 109

- 11,159
- 5
- 49
- 70
I think the main difference is in validating the XML. A random string will not pass base64Binary validation, whereas a base64Binary content will pass string validation.
If I expect base64Binary content in the XML, and dont want a random string.