Scope
in VoiceXML
Scope
defines the order of precedence for tags
used in VoiceXML depending on where they
are placed within an application. Variables,
links, grammars, and event handling all
utilize scope. For example, variables
have five distince levels of scope:
session
- read only variables pertaining to
an entire user session. These variables
are declared by the platform and cannot
be set within VoiceXML documents.
application
- declared by the <var>
element as children of the
root applications
<vxml> tag (declared
directly under this tag and no other).
They exist while the root document is
loaded and can be accessed at any level
within any document in the application.
document
- declared as children of a supporting
document's <vxml>
tag. They are initialized upon loading
the supporting document and may be accessed
only within that document.
dialog
- declared as children of <form>
or <menu>,
these variables are accessible only
within that dialog element and are initialized
when the form is visited. If declared
inside of executable content, initialization
occurs when the content is executed.
Form/field item variables initialize
as the form item is collected (see Tutorials1
& 2).
(anonymous)
- Each <block>,
<filled>,
and <catch>*
element defines a new anonymous scope
in which variables may be declared.
Declaring
variables
The
<var> element
is used to declare variables with the
mandatory name
attribute to specify the variable name.
The variable may optionally be initialized
with a given value through the use of
the expr
attribute. Here is an example of declaring
an application wide variable: