Error message

Workarounds and usability notes.

Error message

Postby John Robin Dove » Thu Feb 20, 2020 11:57 am

Hi Clifton,
This part of my XML file:

<limits>
<function name="myTrigger" event="trigger" params="" useTB="true">
<![CDATA[
tbfunction_pgTBObjSet("warning", "visible", true);
]]>
</function>
</limits>


produces this error:

The following error has occurred:
SyntaxError: missing ) after formal parameters (line number 5)

Any idea why please?

UPDATE

If I remove useTB="true" the error disappears. I now have another problem but I'll start a new topic for this.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Error message

Postby Clifton » Thu Feb 20, 2020 4:09 pm

Just to make sure there is no buggy XML/PowerPac behavior, I created this XML file:
    <?xml version="1.0" encoding="utf-8"?>
    <page>
    <config delay="">
    <!--Nothing to configure.-->
    </config>

    <limits>
    <text>
    Waiting for text to change ...
    </text>

    <function name="myTrigger" event="trigger" params="" useTB="true">
    <![CDATA[
    tbfunction_pgTBObjSet(this.name, 'text', 'Hello, how are you?');
    ]]>
    </function>
    </limits>

    <!--Additional <config#> ... </config#> sections as required.-->
    <config2 delay="350">
    <exeJavascriptDirect>
    <![CDATA[
    /* Trigger <limits> after 5000ms
    Result will be that the text will change in the field.
    ***/
    tbfunction_pgTBObjSet('limits', 'trigger', '', 5000);
    ]]>
    </exeJavascriptDirect>
    </config2>
    </page>

Then I created a 1 page ToolBook with a single field named "limits".
Exported the file and it worked perfectly!

So what "may" be the problem you are having?
  • The error message your are receiving is generated by PowerPac's XML Engine and is telling you that when the PowerPac tried to compile "something" in your XML file, it encountered the missing syntax error. These errors are pretty accurate. If a closing parenthesis is missing, it probably is. BUT, it may not be related to the function your looking at. XML files are processed from top to bottom, so the error likely occurs before the trigger function definition.
  • To troubleshoot this, progressively comment out sections of your XML file until you find where the missing syntax is located. Fortunately, this is easy to do with a single export because all you have to do is edit the XML file and then refresh the browser.
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: Error message

Postby John Robin Dove » Fri Feb 21, 2020 6:22 am

Thanks for your efforts. I took everything out of the XML except this:

<?xml version="1.0" encoding="UTF-8"?>
<page>
<!--The FIRST line defines this as a data XML file.
END-->


<config>
<exeJavascriptDirect>
{ commandLine : "document.title='Médiacours Student';" }
</exeJavascriptDirect>
<!--You should always provide at least one config section even if it is empty-->

<stylesheet>
../media/button.css
</stylesheet>
</config>


<limits>
<function name="myTrigger" event="trigger" params="" useTB="true">
<![CDATA[
tbfunction_pgTBObjSet("warning", "visible", true);
]]>
</function>
</limits>
</page>


This is exactly what was left and it stiil produced the same error. If I take out useTB="true" there is no problem and the trigger performs as required. Maybe it's my dodgy Toolbook 9.01 version patched from 9.0?
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Error message

Postby Clifton » Fri Feb 21, 2020 9:03 am

Actually your <exeJavascriptDirect> code IS failing. When I run your example, I don't necessarily get an error, but the document title does not get applied either. The likely reason is the French characters, which are probably not supported as raw XML. To get your <exeJavascriptDirect> to run you would have to wrap it in a <![CDATA[ ... ]]> tag so the XML interpreter avoids trying to manipulate it.

BUT, the proper way to run <exeJavascriptDirect> in an XML is like this:
    <exeJavascriptDirect>
    <![CDATA[
    document.title = 'Médiacours Student';
    ]]>
    </exeJavascriptDirect>
This is hugely flexible in that you can just write any JavaScript code between the tags, rather than worrying about the single and double quotes, etc. You are not limited by simple single lines of code. Instead you can define functions and events and execute them within the XML this way. You can even call other PowerPac functions within the tags.
 
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: Error message

Postby John Robin Dove » Fri Feb 21, 2020 10:10 am

Yes, I had forgotten about that. In fact I do alter the title successfully further down in this XML while the document is loading like this: document.title = "Médiacours - " + this.myArray[3]; this.myArray[3] is the name of the exercise. Yes I always use the <![CDATA[ ... ]]> tag (except when I forget :roll:) and I realize how important it is as it allows you to use two codes: XML and javascript simultaneously.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Error message

Postby Clifton » Fri Feb 21, 2020 12:10 pm

As a few side notes on the use of <exeJavascriptDirect>:
  • Generally, it should only be run in a <config> or <config#> section.
  • Always wrap the code in <![CDATA[ ... ]]> tag to prevent XML compiler errors.
  • As an alternative, you can use the "load" event to perform the same tasks as <exeJavascriptDirect> but you can you the "load" event anywhere in the XML document. Here is an example:
      <nameOfObject>
      <pgStyleObject>
      [style the object here as desired]
      <pgStyleObject>

      <htmlText>
      <![CDATA[
      [my html code]
      ]]>
      </htmlText>

      <function name="myLoad" event="load" params="e">
      <![CDATA[
      /* CLIFTON: Any JavaScript you enter here will be executed immediately when
      the XML interpreter parses this function. Permits custom executions as soon
      as this element has loaded. Very similar to the Actions Editor on load page event.
      ***/

      ]]>
      </function>
      </nameOfObject>

Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 4 guests

cron