Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Greater than > Less than < inside thymeleaf javascript... Error: The content of elements must consist of well-formed character data or markup

I get this error when I try to insert < or > operators inside the thymeleaf javascript.

My code

<script th:inline="javascript">
    $(document).ready(function () {
        ...
        if(timeRemain < 0){
            ...
        }
        ...
        var result = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds  < 10 ? "0" + seconds : seconds);
        ...         
    });
</script>

Error message

org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.

How can i solve this?

like image 884
Faraj Farook Avatar asked Apr 09 '15 13:04

Faraj Farook


2 Answers

This issue is solved by adding CDATA to the script tag as below

<script th:inline="javascript">
    /*<![CDATA[*/
    ...  
    ...
    ...
    /*]]>*/
</script>
like image 200
Faraj Farook Avatar answered Nov 20 '22 13:11

Faraj Farook


Apart from using CDATA you can also encode < as &lt; and > as &gt;

like image 32
Rahul Tripathi Avatar answered Nov 20 '22 13:11

Rahul Tripathi