escape character in XML text string

Discussion in 'XML' started by Testbruger@intervisit.com, Jan 21, 2004.

  1. Guest

    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
    , Jan 21, 2004
    #1
    1. Advertising

  2. * 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.
    Bjoern Hoehrmann, Jan 22, 2004
    #2
    1. Advertising

  3. Andy Dingley Guest

    On Wed, 21 Jan 2004 21:44:07 GMT, ""
    <> wrote:

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


    Tried an entity ?

    
    Andy Dingley, Jan 22, 2004
    #3
  4. Andy Dingley wrote:
    > On Wed, 21 Jan 2004 21:44:07 GMT, ""
    > <> wrote:
    >
    >
    >>How can I include the character ' 27' into the data so that the XML is
    >>properly formed and not rejected.

    >
    >
    > Tried an entity ?
    >
    > 


    Tried yourself?

    Anyway: doesn't work. The character is illegal in XML, no matter whether
    as entitiy or not.
    Julian Reschke, Jan 22, 2004
    #4
  5. Andy Dingley Guest

    On Thu, 22 Jan 2004 10:35:33 +0100, Julian Reschke
    <> wrote:

    >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 ?)
    Andy Dingley, Jan 22, 2004
    #5
  6. Peter Flynn Guest

    Andy Dingley wrote:
    > On Thu, 22 Jan 2004 10:35:33 +0100, Julian Reschke
    > <> wrote:
    >
    >
    >>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 ?)
    >


    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
    Peter Flynn, Jan 24, 2004
    #6
  7. Andy Dingley Guest

    On Sat, 24 Jan 2004 02:21:44 +0000, Peter Flynn <>
    wrote:

    >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.
    Andy Dingley, Jan 24, 2004
    #7
  8. Andy Dingley wrote:
    > On Sat, 24 Jan 2004 02:21:44 +0000, Peter Flynn <>
    > wrote:
    >
    >
    >>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.


    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
    Julian Reschke, Jan 24, 2004
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff S
    Replies:
    12
    Views:
    13,844
    Jeff S
    Nov 10, 2003
  2. slomo
    Replies:
    5
    Views:
    1,506
    Duncan Booth
    Dec 2, 2007
  3. Sanjeev
    Replies:
    3
    Views:
    1,696
    Andrea Francia
    May 3, 2008
  4. Mausam
    Replies:
    4
    Views:
    854
  5. VUNETdotUS
    Replies:
    3
    Views:
    627
    VUNETdotUS
    Nov 2, 2007
Loading...

Share This Page