XML 架构。Base64binary 类型 vs String 类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34411824/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XML Schema. Base64binary type vs String type
提问by kirill.login
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"?
我需要从某个 XML 元素解码 Base64 字符串。由type="xs:base64binary"定义的元素和由定义的元素之间有什么区别type="xs:string"吗?一些 XSD 开发人员拒绝将编码字符串标记为 base64binary。如果没有区别,有什么用type="xs:base64binary"?
采纳答案by CodeManX
If I understand the specscorrectly, there is a semantic difference.
如果我正确理解规范,则存在语义差异。
A base64Binaryelement contains arbitrary, binary data that has been encoded as base64, which makes it basically a string (or at least string-compatible).
甲base64Binary元素包含已被编码为base64任意的,二进制数据,这使得它基本上是一个字符串(或至少串兼容)。
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 base64Binaryto indicate that the decoded data is not suitable for human consumption, where as stringis readable/printable.
您可以使用base64Binary来指示解码的数据不适合人类消费,而string可读/可打印。
回答by kjhughes
There definitely is a difference between base64Binaryand stringin XSD:
XSDbase64Binary和stringXSD之间肯定存在差异:
- base64Binaryrepresents binary data encoded in Base64. Its value spaceis the set of fixed length binary octets. Its
lexical space is limited to
a-z,A-Z,0-9,+,/,=, plus whitespace. - stringrepresents character data. Its value spaceis the set of finite-length sequences of characters. Its lexical space is unconstrained beyond having to consist of XML characters.

