VoiceXML 2.1 Development Guide Home  |  Frameset Home

  SRGS-SISR: Grammar Basics  |  TOC  |  SRGS-SISR: DTMF grammars  

grXML 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 VXML documents.

Grammar Fetching

Let's first take on some core 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="application/grammar-xml"/>


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==

<?xml version= "1.0"?>

<grammar xmlns="http://www.w3.org/2001/06/grammar" xml:lang="en-US" root = "MYRULE">
<cfheader name="Cache-Control" value= "no-cache">
<cfheader name="Expires" value="#Now()#">

<cfcontent type = "text/almost_plain">

<rule id="MYRULE" scope="public">
    <one-of>

      <item> tricky <tag> <![CDATA[  <MySlot "Run DMC"> ]]>  </tag>  </item>
  </one-of>
</rule>
</grammar>




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 cahed 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
agonzalez
5/19/2006 9:49 AM (EDT)
is the example ok?

<rule id="MYROOT" scope="public">
should be :
<rule id="MYRULE" scope="public">

or  <grammar src="MyGrammar.cfm#MYRULE" type="text/gsl"/>
should be :
<grammar src="MyGrammar.cfm#MYROOT" type="text/gsl"/>

where is #myrule pointing? from the grammar src="MyGrammar.cfm#MYROOT"
mikethompson
5/19/2006 11:24 AM (EDT)
Hello Angel,

I believe you have found a typo here.  Either way would work as long as the rule id matched the anchor on the grammar reference.  So, if the grammar src was #MYRULE then the rule id in the grammar should be MYRULE as well.  As it stands now, #Myrule is pointing nowhere because the rule id is not the same.  I'll alert the keepers of the documentation to see that they implement a fix in the next internal build.

Regards,
Mike Thompson
Voxeo Extreme Support
Khamyl
7/10/2006 11:44 AM (EDT)
Good day!

If we are speaking about grXML format, shouldn't there be

<grammar src="MyGrammar.cfm#MYRULE" type="text/application-xml"/>

or something related to grXML instead of

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

And one more thing!.. why we do not define any 'type' atribute in <grammar> tag in myGrammar.cfm file?

THX! Khamyl
MattHenry
7/10/2006 5:39 PM (EDT)


Hello again Khamyl,


Let's address the questions one-by-one, shall we?

- Regarding the 'type' specified in the example, this is illustrative of a bad copy/paste on my part. You are correct in that this really should be defined as "application/grammar-xml" for this specific SRGS grammar.

- In reference to your comment about the 'type' not being specified within the extrnal file itself, note that this is really only required when referncing an external grammar; this attribute is only required in the grammar invocation, not within the file itself.


Hope this clears things up,

~Matthew Henry


login
  SRGS-SISR: Grammar Basics  |  TOC  |  SRGS-SISR: DTMF grammars  

© 2012 Voxeo Corporation  |  Voxeo IVR  |  VoiceXML & CCXML IVR Developer Site