Reputation: 961
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"
?
Upvotes: 29
Views: 75506
Reputation: 31
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.
Upvotes: 2
Reputation: 11915
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.
Upvotes: 23
Reputation: 111726
There definitely is a difference between base64Binary
and string
in XSD:
a-z
, A-Z
, 0-9
, +
, /
, =
, plus
whitespace.Upvotes: 43