将转义字符0x1b保存在XML文件中 [英] Saving an escape character 0x1b in an XML file

查看:868
本文介绍了将转义字符0x1b保存在XML文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个应用程序可以使用内部打印机字体与打印机进行通信。这需要使用字体描述属性以二进制格式发送一些数据。



要发送的一个字符是转义字符(0x1b)。系统的状态和更改的所有选项将被保存在XML文件中,但是当我们尝试写入值时,我们得到以下异常:

  System.InvalidOperationException:XML文档中有一个错误(1009,26)。 ---> System.Xml.XmlException:'[一些小的向后箭头符号]',十六进制值0x1B,是一个无效的字符。 

我不太确定为什么这个箭头用作逃脱,但它适用于打印机。当我们尝试将其保存在XML文件中时,会发生错误。任何建议?

解决方案

iSimilar问题:



如何在xml中避免unicode字符0x1F?



所以不推荐的方法

  

或使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆