- Barging in with bargein
- Multiple Document Applications
- Multidocument Transitions
- Throwing and Catching Events
- Application-Specific Events
- Event Names and Prefix Matching
- Summary
Multiple Document Applications
A Voice XML multidocument application is built around a single root document and one or more leaf documents. Any grammars or variables defined in the root document are visible to leaf documents.
To set things up so that multiple documents work together as one application, one document is selected as the application root document; the others are considered leaf documents. To be considered a root document, all that is needed is for another document to name you as its application document in the <vxml> element.
When an application is configured with root and leaf documents, each time a leaf document is loaded, a check is made to see whether the root document is also loaded. If not, the server first loads the root. The application root document remains in scope until the server is told to load a document that belongs to a different application.
When a leaf document loads, causing a root document to also load, none of the dialogs in the root document is executed. Execution will begin in the leaf document.
Listing 3 illustrates a multidocument application with a root and two leaf documents.
Listing 3 An application root document and two leaf documents
Application root document (myroot.vxml)
1 <?xml version="1.0" encoding="UTF-8"?> 2 <vxml xmlns="http://www.w3.org/2001/vxml" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://www.w3.org/2001/vxml 5 http://www.w3.org/TR/voicexml20/vxml.xsd" 6 version="2.0"> 7 <var name="app" expr="’world’"/> 8 9 <link next="baseball.vxml"> 10 <grammar type="application/srgs+xml" root="root" version="1.0"> 11 <rule id="root" scope="public">baseball</rule> 12 </grammar> 13 </link> 14 </vxml>
Leaf document (mainmenu.vxml)
16 <?xml version="1.0" encoding="UTF-8"?> 17 <vxml xmlns="http://www.w3.org/2001/vxml" 18 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 19 xsi:schemaLocation="http://www.w3.org/2001/vxml 20 http://www.w3.org/TR/voicexml20/vxml.xsd" 21 version="2.0" application="myroot.vxml"> 22 23 <menu id="mainmenu" dtmf="true"> 24 <prompt> 25 Welcome to the info <value expr="app"/> hotline. 26 If you know the category you want, 27 you may say it at any time. 28 <enumerate> 29 For <value expr="_prompt"/>, press <value expr="_dtmf"/> 30 </enumerate> 31 </prompt> 32 33 <choice next="#sports">sports</choice> 34 <choice next="#weather">weather</choice> 35 </menu> 36 37 <menu id="sports"> 38 <property name="inputmodes" value="dtmf"/> 39 <prompt> 40 For baseball press 1, For football press 2, For soccer 41 press 3. 42 </prompt> 43 <choice dtmf="1" next="baseball.vxml"/> 44 <choice dtmf="2" next="#football"/> 45 <choice dtmf="3" next="#soccer"/> 46 </menu> 47 48 49 <form id="weather"> 50 <block> you have reached the weather it rains or not hotline 51 </block> 52 </form> 53 54 <form id="football"> 55 <block> you have reached the football, kick kick hotline 56 </block> 57 </form> 58 59 <form id="soccer"> 60 <block> you have reached the soccer, push push hotline 61 </block> 62 </form> 63 64 65 </vxml>
Leaf document (baseball.vxml)
66 <?xml version="1.0" encoding="UTF-8"?> 67 <vxml xmlns="http://www.w3.org/2001/vxml" 68 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 69 xsi:schemaLocation="http://www.w3.org/2001/vxml 70 http://www.w3.org/TR/voicexml20/vxml.xsd" 71 version="2.0" application="myroot.vxml"> 72 73 74 <form> 75 <block>welcome to baseball news. brought to you by 76 the info <value expr="app"/> hotline. 77 </block> 78 </form> 79 80 </vxml>
In the Listing 3 example, an initial loading of mainmenu.vxml (line 16) forces the loading of myroot.vxml (line 1). This creates the application variable app (line 7) and defines a link (line 9) that forces the transition to baseball.vxml whenever the user says "baseball". When the application starts up, the user hears the mainmenu dialog.
In this sample dialogue, the user jumps to hear about baseball.
S: Welcome to the info world hotline. If you know the category you want, you may say it at any time. For sports, press 1. For weather, press 2. U: Baseball. S: Welcome to baseball news, brought to you by the info world hotline.
Note that when the transition to baseball.vxml occurs, the variable app, defined in the root document (line 7) is made available (line 76). Note also that the <vxml> element (lines 2–6) does not have an application attribute specified. It’s up to a leaf document to refer to its application document in the application attribute of its <vxml> element (lines 21 and 71).
If a document is loaded that does not specify an application attribute, this document becomes the new root document of new application—with its own context.