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"
?
Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The term Base64 originates from a specific MIME content transfer encoding.
Artjom B. Base64 is not encryption. But yes, different input strings will always encode to different Base64-encoded strings, and the same input string will always encode to the same Base64-encoded string. It's not a hash though, so small changes in the input will only result in small changes in the output.
There is no way to distinct string and base64 encoded, except the string in your system has some specific limitation or identification. Show activity on this post. This snippet may be useful when you know the length of the original content (e.g. a checksum). It checks that encoded form has the correct length.
There definitely is a difference between base64Binary
and string
in XSD:
a-z
, A-Z
, 0-9
, +
, /
, =
, plus
whitespace.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With