escape character in XML text string

T

Testbruger

Hi,

I am generating a XML based file for a system that will generate PCL code
from textual <text>..</text> tag items. The PCL string needs escape
characters. The string within this tag will be transparently forward to a
device that understands escape characters.

How can I include the character ' 27' into the data so that the XML is
properly formed and not rejected.

char c = '\u001b';
string = "ab" + c + "de" will not work.

Any ideas?

Gr. Ricardo
 
B

Bjoern Hoehrmann

* (e-mail address removed) wrote in comp.text.xml:
I am generating a XML based file for a system that will generate PCL code
from textual <text>..</text> tag items. The PCL string needs escape
characters. The string within this tag will be transparently forward to a
device that understands escape characters.

How can I include the character ' 27' into the data so that the XML is
properly formed and not rejected.

You cannot include U+001B literally in XML documents, you need some
method to express U+001B in characters that are allowed in XML. In
common use are Base64 and Hex encoding.
 
A

Andy Dingley

Anyway: doesn't work. The character is illegal in XML, no matter whether
as entitiy or not.

Sorry - gettiing late and I was tired. It's in the forbidden range
(I've never understood why - anyone care to explain the reasoning
behind them ?)
 
P

Peter Flynn

Andy said:
Sorry - gettiing late and I was tired. It's in the forbidden range
(I've never understood why - anyone care to explain the reasoning
behind them ?)

Escape sequences are used to control output devices, eg to change fonts,
clear the screen, switch to block graphics mode, and goddess knows what
else.

You really, *really*, REALLY don't want ESC in your output stream, ever,
unless you are writing a device controller.

The OP wanted to use an XML stream for device control, which IMHO is
A Bad Idea. The simple solution is to insert a placeholder like <ESC/>
and pass the file through a transformation stage that *will* output
a \027 character.

///Peter
 
A

Andy Dingley

You really, *really*, REALLY don't want ESC in your output stream, ever,
unless you are writing a device controller.

But what if I am ?

 is a good "XML-like" solution to handling these potentially
volatile characters. Represented as an entity, it ain't going nowhere
(equally for your <ESC/> example).

Expanding the entities (&amp; as an example) already transforms the
input from well-formed XML to something else. I don't see the possible
presence of \027 in here as any more risky than a serial cable's
ability to carry that same octet.
 
J

Julian Reschke

Andy said:
But what if I am ?

 is a good "XML-like" solution to handling these potentially
volatile characters. Represented as an entity, it ain't going nowhere
(equally for your <ESC/> example).

Expanding the entities (&amp; as an example) already transforms the
input from well-formed XML to something else. I don't see the possible
presence of \027 in here as any more risky than a serial cable's
ability to carry that same octet.

In fact, generating *XML* and sending it directly to a device that
expects ESCs makes little sense. However, it's perfectly plausible to
use XSLT's text output method to produce this kind of output. Right now,
this doesn't work out-of-the-box.

One approach is to define placeholders such as <esc/> and have a special
output method to translate those (I think many Java based XSLT engines
allow you to define custom output methods).

This issue may also get solved by XML 1.1
(<http://www.w3.org/TR/xml11/#sec-xml11>). Is anybody aware of changes
in XSLT 2.0?

Julian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top