Xml Schema. Base64Binary Type vs String Type

Xml Schema. Base64Binary Type vs String Type

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"?

2 Answers

There definitely is a difference between base64Binary and string in XSD:

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.