DHTMLX Documentation

Handling special characters


Special characters in XML

When data loaded from XML file|string there are some special characters which can cause problem.
For XML those are  < > &

There are two ways to store them in XML

a) Escaping - the characters can be replaced with related XML entities
    > => &gt;
    < => &lt;
    & => &amp;
    
b) use CDATA section - any data can be stored inside CDATA section


    <cell> Specail characters < > &</cell>      <= Incorrect
    <cell> Specail characters &lt; &gt; &amp;</cell>        <= Correct
    <cell><![CDATA[ Specail characters < > &]]></cell>        <= Correct
   

Special encodings in XML

Component is encoding agnostic, it will support any encoding which supported by browser, just be sure to have correct XML header
    <?xml version="1.0" encoding="ISO-8859-1" ?>
The encoding attribute must specify correct encoding value. ( if such attribute ommited, UTF-8 will be used by default)
   

Special characters in dhtmlxGrid

By default grid threat all incoming data as HTML, so it will convert any HTML special chars ( and again they are include < > & characters )
To resolve such issue , the grid supports "pure" text excell. In contrast with default ones - they will not allow any HTML content inside them, but will preserve any special characters and allow correct edition of such special chars.

There are next "pure text" cell types
    rotxt - readonly text excell
    edtxt - single line editor text excell
    txttxt - multi-line text editor
    corotxt - text only selectbox
   
mygrid.setColTypes("rotxt")
...
mygrid.addRow(1,"<&>"); // will render text correctly

Special characters serialization

When grid serialized back to XML, special characters in cells can corrupt result XML. To prevent such issue , you can force usage of CDATA while serialzation. ( CDATA make any content safe, so result XML will be valid in any case )
Such mode can be enabled with  setSerializationLevel command

grid.setSerializationLevel(false,false,false,false,false,true);