Static grammars

The following example illustrates the use of grammars in a Web-based voice application for a restaurant:

<?xml version="1.0" encoding="iso-8859-1"?>
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml" xml:lang="en-US">
 <form>
  <field name="drink">
    <prompt>What would you like to drink?</prompt>
    <grammar mode="voice" version="1.0" root="drinks">
      <rule id="drinks">
        <one-of>
          <item> coffee </item>
          <item> tea </item>
          <item> orange juice </item>
          <item> milk </item>
          <item> nothing </item>
        </one-of>
      </rule>
    </grammar>
  </field>
  <field name="sandwich">
    <prompt>What type of sandwich would you like?</prompt>
    <grammar src="sandwich.grxml"/>
  </field>
  <filled>
    <submit next="/servlet/order"/>
  </filled>
 </form>
</vxml>

In this example, the first grammar (for drinks) consists of a single rule, specified inline. In contrast, the second grammar (for sandwiches) is contained in an external grammar file, shown below:

<?xml version="1.0" encoding="ISO-8859-1"?>
<grammar version="1.0" xmlns="http://www.w3.org/2001/06/grammar"
		xml:lang="en-US" mode="voice" root="sandwich" tag-format="semantics/1.0">
 <rule id="sandwich">
   <ruleref uri="#ingredient"/>
   <item repeat="0-">
     <item repeat="0-1"> and </item>
     <ruleref uri="#ingredient"/>
   </item>
   <item>
     <item> on </item>
     <ruleref uri="#bread"/>
   </item>
 </rule>
 <rule id="ingredient" scope="private">
   <one-of>
     <item> ham </item>
     <item> turkey </item>
     <item>
      <item> swiss </item>
      <item repeat="0-1"> cheese </item>
     </item>
   </one-of>
 </rule>
 <rule id="bread" scope="private">
   <one-of>
     <item> rye </item>
     <item> white </item>
     <item>
      <item repeat="0-1"> whole </item>
      <item> wheat </item>
     </item>
   </one-of>
 </rule>
</grammar>

Here, the ingredient and bread rules are private, meaning that they can only be accessed by other rules in this grammar file. The sandwich rule is public, meaning that it can be accessed by specifying this grammar file or by referencing the fully-qualified name of the sandwich rule.

A typical dialog might sound like this:

System: What would you like to drink?
User: Coffee.
System: What type of sandwich would you like?
User: Turkey and swiss on rye.

At this point, the system has collected the two fields needed to complete the order, so it executes the <filled> element, which contains a <submit> that causes the collected information to be submitted to a remote server for processing.