Larson Technical Services: Voice Technology Consulting

Exercise 9.2

Construct a VoiceXML form that captures a query for accessing the following relational database table:

  • Table name: Employee
  • Column name: Name
  • Column name: ID
  • Column name: Monthly salary
  • Column name: Street address
  • Column name: City
  • Column name: State (or country)
  • Column name: Postal code
    Hint: keep the query simple by allowing only one condition on each field (e.g., ID = 14234) and no disjunctions (ID=14234 or name= “Jones”).


<?xml version="1.0"?> 

<!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" 
 "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd">
 <vxml version="2.0" xmlns = "http://www.w3.org/2001/vxml">

<!--  Exercise 9.2                      --> 
<!--  Formulate database query  --> 

<form id = "database_query">

<block>
   <prompt>
        Database query system.  Speak value or say skip for each field.
   </prompt>
</block>
<!-- pass indicates that the user does not specify a value for the field -->  

     <field name="name"> 
        <prompt>Employee name?</prompt>
        <grammar type="application/grammar+xml" 
          xml:lang = "en" root="employee_name">
         <rule id = "employee_name" scope = "public">
              <one-of>
                   <item>skip</item>
                  <item>sam</item>
                  <item>fred</item>
              </one-of>
          </rule> 
       </grammar>
     </field>

     <field name="id"> 
        <prompt>employee number?</prompt>
        <grammar type="application/grammar+xml" 
          xml:lang = "en" root="employee_id">
          <rule id = "employee_id" scope = "public">
               <one-of>
                   <item>skip</item>
                   <item>seventeen</item>
                   <item>nineteen</item>
               </one-of>
           </rule> 
       </grammar>
     </field>

     <field name="salary" type = "digits"> 
        <prompt>monthly salary?</prompt>
        <grammar type="application/grammar+xml" 
             xml:lang = "en" root="salary">
             <rule id = "salary" scope = "public">
                 <one-of>
                     <item>skip</item>
                     <item>2000</item>
                     <item>3000</item>
                 </one-of>
             </rule> 
       </grammar>
     </field>

     <field name="address"> 
        <prompt>street address?</prompt>
        <grammar type="application/grammar+xml" 
               xml:lang = "en" root="street">
              <rule id = "street" scope = "public">
                   <one-of>
                       <item>skip</item>
                       <item>elm</item>
                       <item>main</item>
                  </one-of>
              </rule> 
       </grammar>
    </field>

     <field name="city"> 
        <prompt>city?</prompt>
        <grammar type="application/grammar+xml" 
             xml:lang = "en" root="city">
             <rule id = "city" scope = "public">
                  <one-of>
                      <item>skip</item>
                      <item>seattle</item>
                      <item>portland</item>
                  </one-of>
              </rule> 
        </grammar>
     </field>

     <field name="state"> 
        <prompt>state?</prompt>
        <grammar type="application/grammar+xml" version="1.0"
             xml:lang = "en" root="USState">
               <rule id = "USState" scope = "public">
                   <one-of>
                      <item>skip</item>
                      <item>oregon</item>
                      <item >washington</item>
                   </one-of>
              </rule>
        </grammar>
     </field>

     <field name="zip"> 
        <prompt>zip code?</prompt>
        <grammar type="application/grammar+xml" version="1.0"
             xml:lang = "en" root="zip">
               <rule id = "zip" scope = "public">
                   <one-of>   
                      <item>skip</item>
                      <item>00000</item>
                      <item >11111</item>
                   </one-of>
              </rule>
        </grammar>
     </field>
     <block>
          <prompt>
          employee name is <value expr = "name"/>
          employee number is <value expr = "id"/>
          employee salary is <value expr = "salary"/>
          street address is <value expr = "address"/>
          city is <value expr = "city"/>
          state is <value expr = "state"/>
          zip code is <value expr = "zip"/>
          </prompt>
     </block>
</form>

<!-- the backend application constructs an SQL request from the parameters-->
<!-The "skip" value indicates that this field is not involved with the query  -->
<!-- and submits the SQL to a relational database management system  -->
</vxml>

Return to the Instructor’s Page

Comments are off for this post