DHTMLX Docs & Samples Explorer

Index
dhtmlxgrid

## Handling Special Characters

### Special Characters in XML

When data is loaded from XML file|string, there are some special characters that can cause problem. For XML these characters are ”<”, ”>”, and ”&amp;”. There are two ways to store them in XML:

- Escaping - the characters can be replaced with related XML entities:

        > => &amp;gt;
        < => &amp;lt;
        &amp; => &amp;amp;

- Using CDATA section - any data can be stored inside CDATA section:

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

### Special Encodings in XML

The component is encoding-agnostic. It will support any encoding that is supported by the browser. The user should 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 is omitted, UTF-8 will be used by default).

### Special Characters in dhtmlxGrid

By default, the grid treats all incoming data as HTML, so it will convert any HTML special character (including <, > and &amp; characters). To resolve such issue, the grid supports pure text excell. In contrast with default ones, these excells will not allow any HTML content inside them, but will preserve any special characters and allow correct edition of such special chars.

The following pure text cell types are available:

- rotxt - readonly text excell;
- edtxt - single-line editor text excell;
- txttxt - multi-line text editor;
- corotxt - text only selectbox.

        <script>
            grid.setColTypes("rotxt") // type codes list (default delimiter is ",")
            ...
            grid.addRow(1,"<&amp;>"); // will render the text correctly
        </script>

### Serialization of Special Characters

When the grid is serialized back to XML, special characters in cells can corrupt the result XML. To prevent such issue, the user can force the usage of CDATA while serialization (CDATA makes any content safe, so the resulting XML will be valid in any case).

Such mode can be enabled with setSerializationLevel() command.