将转义字符0x1b保存在XML文件中 [英] Saving an escape character 0x1b in an XML file
问题描述
要发送的一个字符是转义字符(0x1b)。系统的状态和更改的所有选项将被保存在XML文件中,但是当我们尝试写入值时,我们得到以下异常:
System.InvalidOperationException:XML文档中有一个错误(1009,26)。 ---> System.Xml.XmlException:'[一些小的向后箭头符号]',十六进制值0x1B,是一个无效的字符。
我不太确定为什么这个箭头用作逃脱,但它适用于打印机。当我们尝试将其保存在XML文件中时,会发生错误。任何建议?
iSimilar问题:
所以不推荐的方法

或使用D-D的答案中提到的base-64
We have an application that communicates with printers using their internal printer fonts. This requires sending some data in a binary format using a font description property.
One of the characters to be sent is an escape character (0x1b). The state of the system and all options changed are later saved in an XML file, but when we try to write the value, we get the following exception:
System.InvalidOperationException: There is an error in XML document (1009, 26). ---> System.Xml.XmlException: '[Some small backwards arrow symbol]', hexadecimal value 0x1B, is an invalid character.
I'm not really sure why this arrow functions as escape, but it works on the printer. The error occurs when we try to save it in an XML file. Any suggestions?
iSimilar question to:
How do I escape unicode character 0x1F in xml?
So either the not recommended approach of

or using base-64 as mentioned in Darin's answer
这篇关于将转义字符0x1b保存在XML文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!