0

I understand why control characters are illegal in XML 1.0, but still I need to store them somehow in XML payload and I cannot find any recommendations about escaping them. I cannot upgrade to XML 1.1.

How should I escape e.g. SOH character (\u0001 - standard separator for FIX messages)?

The following doesn't work:

<data>&#x01;</data>
Michal Kordas
  • 10,475
  • 7
  • 58
  • 103
  • Would it not make more sense to change the XML schema so that you didn't need to include the separator - i.e use additional XML elements? – Rowland Shaw Feb 19 '18 at 09:07
  • XML Schema is fixed in my case. I have just one tag where I can store original FIX trading message payload. I can do escaping, but I cannot put any additional tags. – Michal Kordas Feb 19 '18 at 09:13

3 Answers3

3

One way is to use processing instructions: <?hex 01?>. But that only works in element content, not in attributes. And of course the processing instruction needs to be understood by the receiving application.

You could also use elements: <hex value="01"/> but elements are visible in an XSD schema or DTD, while processing instructions are hidden.

Another approach is that if a piece of payload can contain such characters, then put the whole payload in Base64 encoding.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
0

It's quite common in logging/printing of FIX messages to substitute SOH with another character like '|'. Could you do the same here?

Andy Lynch
  • 1,228
  • 9
  • 15
  • We tried to use pipe some time ago, but then it occurred that messages themselves may contain `|` in trade comment. Actually every valid visible character could go to trade comment, so we struggle to find correct replacement. – Michal Kordas Feb 28 '18 at 10:45
  • I have been known to use a character from the Unicode private use area in these kinds of cases, but it depends on the context of course, and how confident you can be that no one will be trying to use the private use area for something else. – Norm Apr 23 '22 at 06:21
0

My company ended up adding our own markup before XML: {1}. You also have to escape the { and } braces as {123} and {125}. The when reading the XML you have to do your own parse of the embedded codes.