Ada
Ada

Reputation: 31

xml "<" parsing error

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

Answers (4)

Krishna K
Krishna K

Reputation: 1975

Use

if (values.length - 1 > current) { 

}

:)

Upvotes: 2

sitifensys
sitifensys

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

Lightness Races in Orbit
Lightness Races in Orbit

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

Anirudh Ramanathan
Anirudh Ramanathan

Reputation: 46778

Put it in a <![CDATA[ ...... ]]> and then try

<script type="text/javascript">
//<![CDATA[
..
..
your code
..
..
//]]>
</script>

Upvotes: 2

Related Questions