JavaScript in HTML/XML: not well formed error

456 views Asked by At

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">
2

There are 2 answers

1
kjhughes On BEST ANSWER

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

<script>
<![CDATA[
     JaveScript code here
]]>
</script>
0
lkrocek On

Much better solution is move out your script code into separated file and use src attribute to define path, you won't need work with cdata anymore.