VoiceXML 2.1 Development Guide Home  |  Frameset Home

  GSL Basics  |  TOC  |  Universal Grammars  

GSL Grammar Hints

If we are designing an application with a small number of available caller options, then chances are that you'll either want to use an inline structure, or use the menu and option elements to keep the code nice and compact. However, if you have more complicated grammar/subgrammar structures that contain a lot of options, then you might well want to go with an external grammar reference in order to reduce clutter in your XML documents.

Grammar Fetching

Let's first take on some core GSL grammar facts that will get us started on the right foot. To start with, if we are using a fairly large external grammar file, we don't want our callers to experience any delays while the grammar is being fetched and compiled. For this reason, we recommend that you use the following property setting within the root document of your code:


  <property name="grammarfetchint" value="prefetch"/>


Note that this setting is enabled by default for some browsers, while others use the 'safe' setting. Therefore, it is always better to have this value user-defined in your code to retain maximum flexibility and platform compliance.

Grammar Caching

External grammar files follow the same caching rules as XML documents do. Either we set cache control headers on the server side, or we set it on a per-case basis within each file itself. However, there is a very important fact to keep in mind when using a grammar file extension other than'
.grammar'. If we specify cacahing headers within a grammar via server side language, then our file extension is going to change as well, predictably enough. As such, we will need to also return a valid MIME type to the Voice browser, else we will likely get a fatal compilation error. To illustrate, let's take a look at the below external grammar file:


  <grammar src="MyGrammar.cfm#MYRULE" type="text/gsl"/>


Note that the above grammar references a grammar of type '.cfm', (Cold Fusion), which will likely contain CF-specific caching headers, and possibly some dynamic data:

==MyGrammar.cfm==

<cfheader name="Cache-Control" value= "no-cache">
<cfheader name="Expires" value="#Now()#">

<cfcontent type = "text/almost_plain">

MAINMENU [
  [ tricky] {<FieldName "Run DMC">}
 



In looking over this file, it is evident that we do, in fact have some caching headers set, 'Cache-Control', and 'Expires'. These two lines ensure that any changes we make to the grammar are reflected immediately when calling the application, as the grammar file will not be using a cached copy. Note the next line in particular:


  <cfcontent type = "text/almost_plain">


This line of code is absolutely necessary, as it tells the Voice Browser what the MIME type is. Without this line of code, we will see application failures.  A detailed list of MIME type headers for several server side languages are detailed below:

JSP

response.setHeader("Content-type", "application/x-gsl");


ASP

SetContentType("text/html; charset=XXXXX");


PHP

header('Content-type: application/x-nuance-gsl');


Perl

print "Content-type: text/html\n\n";


Cold Fusion

<cfcontent type = "text/almost_plain">




  ANNOTATIONS: EXISTING POSTS
0 posts - click the button below to add a note to this page

login

  GSL Basics  |  TOC  |  Universal Grammars  

© 2003-2008 Voxeo Corporation  |  Voxeo IVR  |  VoiceXML & CCXML IVR Developer Site