Changeset 2969

Show
Ignore:
Timestamp:
07/08/07 15:43:48 (5 years ago)
Author:
michael
Message:

Fix for quoting XML entities.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/java/org/sarugo/xtc/XMLWriter.java

    r2840 r2969  
    8080                write(name); 
    8181                write("=\""); 
    82                 write(String.valueOf(value)); 
     82                write(escapeXml(String.valueOf(value))); 
    8383                write("\""); 
    8484        } 
     
    8787                closeOpenElement(); 
    8888                write("<!-- "); 
    89                 write(String.valueOf(comment)); 
     89                write(escapeXml(String.valueOf(comment))); 
    9090                write(" -->"); 
    9191        } 
     
    9393        public void writeText(Object text) throws IOException { 
    9494                closeOpenElement(); 
    95                 write(String.valueOf(text)); 
     95                write(escapeXml(String.valueOf(text))); 
    9696        } 
    9797 
     
    101101        } 
    102102 
     103        public static String escapeXml(String str) { 
     104        str = str.replace("&","&amp;"); 
     105        str = str.replace("<","&lt;"); 
     106        str = str.replace(">","&gt;"); 
     107        str = str.replace("\"","&quot;"); 
     108        str = str.replace("'","&apos;"); 
     109        return str; 
     110    } 
    103111}