javascripthtmljsonxmlhbbtv

JavaScript in HTML/XML: not well formed error


I'm trying to get information out of a JSON and I get an error that my XML is not well formed. It points to

if((jsonResponse[0].error) && (jsonResponse[0].error.type == 101)) { 
----------------------------^

Here's the context:

<?xml version="1.0" encoding="UTF-8" ?>
<!--As DOCTYPE either the strict XHTML declaration or 
    "-//HbbTV//1.1.1//EN" "http://www.hbbtv.org/dtd/HbbTV-1.1.1.dtd"
    shall be used as described in the HbbTV-standard: A.2.6.2.-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--Required XML-namespace as described in the HbbTV-standard: A.2.6.2.-->
<html xmlns="http://www.w3.org/1999/xhtml">

Solution

  • Wrap your JavaScript in CDATA section so that && isn't interpretted as markup:

    <script>
    <![CDATA[
         JaveScript code here
    ]]>
    </script>