简体   繁体   English

在 xml 中嵌入十六进制字符

[英]Embed hex character in xml

I have a set of single hecidecimal values represented as string in format "92", "BD", for example, and I need to include them in an xml document.例如,我有一组以“92”、“BD”格式的字符串表示的单个十六进制值,我需要将它们包含在 xml 文档中。

I don't really care about the hexidecimal format I'm actually interested in the content that the hex value represents.我并不真正关心十六进制格式,我实际上对十六进制值所代表的内容感兴趣。 What is the most appropriate approach to get that into xml.将其放入 xml 的最合适方法是什么。 I suppose I could decode to char then just put the char value in xml, as long as the char is valid within xml.我想我可以解码为 char 然后只需将 char 值放入 xml 中,只要 char 在 xml 中有效。

How do I decode the hex string如何解码十六进制字符串

Actually you don't have hexadecimal values represented as strings.实际上,您没有将十六进制值表示为字符串。 You have binary values (octets) represented as hexadecimal strings.您将二进制值(八位字节)表示为十六进制字符串。 It's important to make these distinctions or you can get very muddled.做出这些区分很重要,否则你会变得非常混乱。

How to represent binary values (octets) in XML?如何在 XML 中表示二进制值(八位字节)? XSD supports two representations, xs:hexBinary and xs:base64Binary . XSD 支持两种表示形式, xs:hexBinaryxs:base64Binary Base64 is popular and converters are widely available. Base64 很受欢迎,转换器也广泛可用。 But you can choose your own format if you prefer.但是,如果您愿意,可以选择自己的格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM