Reputation: 31
I'm trying to write some JavaScript code in a gxp file and I get a parsing exception at the "<" character in the "if" construct. Any ideas how to escape it?
<script type="text/JavaScript">
var current = 0;
var values = [];
function goNext() {
if (current < values.length - 1) {
current = current + 1;
update();
}
}
</script>
org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.
Upvotes: 1
Views: 890
Reputation: 2034
This is because your code is "not protected" by a section.
you should try
<script type="text/JavaScript"><![CDATA[
var current = 0;
var values = [];
function goNext() {
if (current < values.length - 1) {
current = current + 1;
update();
}
}
]]></script>
This way the "<" won't be treated as XML.
Upvotes: 1
Reputation: 385405
<
is an XML entity.
Hide the Javascript code from XML:
<script type="text/javascript"><![CDATA[
var current = 0;
var values = [];
function goNext() {
if (current < values.length - 1) {
current = current + 1;
update();
}
}
// ]]></script>
Upvotes: 1
Reputation: 46778
Put it in a <![CDATA[ ...... ]]>
and then try
<script type="text/javascript">
//<![CDATA[
..
..
your code
..
..
//]]>
</script>
Upvotes: 2