kirill.login
kirill.login

Reputation: 961

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

Upvotes: 29

Views: 75506

Answers (3)

Philip Boland
Philip Boland

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

CodeManX
CodeManX

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

kjhughes
kjhughes

Reputation: 111726

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

Upvotes: 43

Related Questions