The application root

A given voice application may be composed of many different VoiceXML documents. However, there is always one root VoiceXML document for the application.

This root document contains items that are available throughout the application:

  • Variables and properties
  • Grammars
  • Event handlers
  • Scripts

These items are available to any VoiceXML subdocument that names the root document in the application attribute of its opening <vxml> element. The root document is the best place to define global variables, global property defaults, universal commands, or any other items that must be available to the entire application.

Items defined in the root document can still be overridden locally at lower levels.

Note: Do not use scripts to assign global property values.

When you load the root document, the system initializes global properties before loading ECMAScript. Thus, you cannot use scripts to assign values to a global property. Here is a well-formed global assignment:

<property name="timeout" expr="'2000'"/>
<!-- The global timeout value will be 2000 -->

Below, the example is not appropriate as a global property in the root document:

<property name="timeout" expr="gettimeout()/>
<!-- gettimeout() is a javascript function. Assignment fails because ECMAScript is not yet loaded. -->

Below, the example always resolves to 1000 when the expression appears in the root document. This is because the system evaluates the expression before creating the browser cookie collection:

<property name="timeout" expr="(browser.document.findCookie('timeout')) ? (browser.document.findCookie('timeout')):1000"/>