Another useful feature that root documents offer IVR developers is the ability to transition from a leaf document back to the root document. This ability allows you to send information back to your root document that has been updated through your leaf documents.
The following IVR example demonstrates how you can do this:
root.vxml (root document):
<?xml version=”1.0″?>
<vxml version=”2.0″>
<var name=”foo”/>
<form>
<block>
<prompt bargein=”false”>
The value leaf is set to <value expr=”leaf”/>.
</prompt>
</block>
</form>
</vxml>
Page1.vxml (leaf document):
<?xml version=”1.0″?>
<vxml version=”2.0″ application=”root.vxml”>
<form>
<block>
<assign name=”foo” expr=”‘bar’”/>
<goto next=”Page2.vxml” maxage=”0″ maxstale=”0″/>
</block>
</form>
</vxml>
Page2.vxml (leaf document):
<?xml version=”1.0″?>
<vxml version=”2.0″ application=”root.vxml”>
<var name=”leaf”/>
<form>
<block>
<assign name=”leaf” expr=”‘rab’”/>
<prompt bargein=”false”>
The value foo is set to <value expr=”foo”/>
</prompt>
<goto next=”root.vxml” maxage=”0″ maxstale=”0″/>
</block>
</form>
</vxml>
From this IVR example, when the application, Page1.vxml, is started, it accesses the variable, “foo”, from the root document, root.vxml, and assigns it the value of string, “bar”. Page1.vxml then transitions to Page2.vxml, which creates a new variable, “leaf”, and assigns it the value of string, “rab”. Page2.vxml then returns the prompt, “The value of foo is set to bar.” After the prompt, Page2.vxml transitions to the root document, root.vxml, which references the variable, “leaf”, from Page2.vxml and returns the prompt, “The value leaf is set to rab.” Thus, it is possible for root documents to reference variables from leaf documents as long as the leaf documents reference the root document.
This ends our discussion on the benefits of using root documents within your VoiceXML IVR code. One thing to keep in mind is that you must reference the root document in each of your leaf documents so that your leaf documents can continue to reference the same content. So, if your root document is entitled rootdocument.vxml, then you must reference the name of this root document in the following way for each of your leaf documents:
<vxml version=”2.0″ application=”rootdocument.vxml”>
If your IVR application reaches a leaf document that no longer references the root document, then the root context becomes destroyed. To clarify this point, think of an example where you have initially declared a variable within your root document and when this variable gets updated in a leaf document, the value is preserved through referencing the root document. If an IVR developer, however, forgets to reference the root document within a leaf document, then the values that get preserved for the variables throughout the leaf document become lost at that point in the application.
Leave a Reply