Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Schema. Base64binary type vs String type

Tags:

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

like image 743
kirill.login Avatar asked Dec 22 '15 08:12

kirill.login


People also ask

Is Base64 string format?

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.

Is Base64 string always same?

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.

Is string Base64 encoded?

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.


2 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.
like image 179
kjhughes Avatar answered Oct 19 '22 05:10

kjhughes


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.

like image 33
CodeManX Avatar answered Oct 19 '22 06:10

CodeManX