xml-rpc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject cvs commit: xml-rpc/src/java/org/apache/xmlrpc XmlWriter.java
Date Mon, 19 Aug 2002 21:09:17 GMT
dlr         2002/08/19 14:09:16

  Modified:    src/java/org/apache/xmlrpc XmlWriter.java
  Log:
  Patch by Adam Megacz <adam@megacz.com> for the following problem (with
  minor improvments by me):
  
  According to XML 1.0, a CDATA section may contain only:
  
    [2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] |
                 [#x10000-#x10FFFF]
  
    http://www.w3.org/TR/2000/REC-xml-20001006#charsets
  
  XmlWriter fails to &#XXXX;-encode characters below 0x20, and emits XML
  which is unparseable by most XML parsers.
  
  Revision  Changes    Path
  1.3       +17 -2     xml-rpc/src/java/org/apache/xmlrpc/XmlWriter.java
  
  Index: XmlWriter.java
  ===================================================================
  RCS file: /home/cvs/xml-rpc/src/java/org/apache/xmlrpc/XmlWriter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -u -r1.2 -r1.3
  --- XmlWriter.java	8 Aug 2002 21:31:50 -0000	1.2
  +++ XmlWriter.java	19 Aug 2002 21:09:16 -0000	1.3
  @@ -293,8 +293,9 @@
       }
   
       /**
  +     * Writes text as <code>PCDATA</code>.
        *
  -     * @param text
  +     * @param text The data to write.
        * @throws IOException
        */
       protected void chardata(String text) throws IOException
  @@ -305,6 +306,11 @@
               char c = text.charAt (i);
               switch (c)
               {
  +            case '\t':
  +            case '\r':
  +            case '\n':
  +                write(c);
  +                break;
               case '<':
                   write(LESS_THAN_ENTITY);
                   break;
  @@ -315,7 +321,16 @@
                   write(AMPERSAND_ENTITY);
                   break;
               default:
  -                write(c);
  +                if (c < 0x20 || c > 0xff)
  +                {
  +                    write("&#");
  +                    write(String.valueOf((int)c));
  +                    write(';');
  +                }
  +                else
  +                {
  +                    write(c);
  +                }
               }
           }
       }
  
  
  

Mime
View raw message