Encode XML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Warrick FitzGerald

    #1

    Encode XML

    Hi All,

    When sending an XML \ SOAP request, if the value looks as follows:

    <TEST> My Test & Son </TEST>

    How should the & be encoded. What is this "TYPE" of encoding called, and
    where can I find a spec on which values should and should not be encoded
    .... I know the W3C will have something but I can't for the life of me
    decode it from their docs.

    Thanks
    Warrick
  • Bob Foster

    #2
    Re: Encode XML

    "Warrick FitzGerald" <nntp.wfitzgera ld@crtman.com> wrote in message
    news:pan.2003.0 8.05.03.37.02.2 38421@crtman.co m...[color=blue]
    > When sending an XML \ SOAP request, if the value looks as follows:
    >
    > <TEST> My Test & Son </TEST>
    >
    > How should the & be encoded.[/color]

    &amp;
    [color=blue]
    > What is this "TYPE" of encoding called[/color]

    Predefined entities. You could also use numeric character references like
    &#38; but that requires looking up (uni) codes.
    [color=blue]
    > and
    > where can I find a spec on which values should and should not be encoded[/color]

    XML 1.0 spec.
    [color=blue]
    > ... I know the W3C will have something but I can't for the life of me
    > decode it from their docs.[/color]

    To boil it down, two characters need to be escaped if they appear in
    attribute values or text outside of CDATA sections:

    & as &amp; or equivalent
    < as &lt; or equivalent

    Two other characters are sometimes handy to escape:

    " as &quot; or equivalent
    ' as &apos; or equivalent

    The other predefined entity is &gt; but AFAIK you never _need_ to use it.

    Bob Foster


    Comment

    • Arto V. Viitanen

      #3
      Re: Encode XML

      >>>>> "Warrick" == Warrick FitzGerald <nntp.wfitzgera ld@crtman.com> writes:

      Warrick> Hi All, When sending an XML \ SOAP request, if the value looks as
      Warrick> follows:

      Warrick> <TEST> My Test & Son </TEST>

      Warrick> How should the & be encoded. What is this "TYPE" of encoding
      Warrick> called, and where can I find a spec on which values should and
      Warrick> should not be encoded ... I know the W3C will have something but I
      Warrick> can't for the life of me decode it from their docs.

      I am not sure if it is enought, but ZSI (a Python SOAP package) uses
      following encodings for text:

      & &amp;
      < &lt;
      "> &gt;
      \015 &#xD;

      and following for attributes

      & &amp;
      < &lt;
      " &quot;
      \011 &#x9;
      \012 &#xA;
      \015 &#xD;

      (from file compat.py)


      --
      Arto V. Viitanen av@cs.uta.fi
      University of Tampere, Department of Computer and Information Sciences
      Tampere, Finland http://www.cs.uta.fi/~av/

      Comment

      • arnold m. slotnik

        #4
        Re: Encode XML

        "Bob Foster" <bobkfoster@com cast.net> wrote in
        news:8mHXa.4845 8$It4.28798@rwc rnsc51.ops.asp. att.net:
        [color=blue]
        > The other predefined entity is &gt; but AFAIK you never _need_
        > to use it.[/color]

        Not quite "never". If you have the string ]]> in content, but not as
        the end of a CDATA section, you need to escape the >.

        --
        a. m. slotnik

        Comment

        • Richard Tobin

          #5
          Re: Encode XML

          In article <Xns93CE7956F8A 35slotnikattnet @204.127.36.1>,
          arnold m. slotnik <slotnik@att.ne t> wrote:
          [color=blue]
          >Not quite "never". If you have the string ]]> in content, but not as
          >the end of a CDATA section, you need to escape the >.[/color]

          Or one of the ]s.

          -- Richard
          --
          Spam filter: to mail me from a .com/.net site, put my surname in the headers.

          FreeBSD rules!

          Comment

          Working...