As part of the http response using the data tag, I receive an xml like
<Addresses>
<entry>205 W LAUREL ST, Glendale</entry>
<entry>20261 E COVINA BLVD, Charter Oak</entry>
<entry>201 E MAGNOLIA BLVD, Burbank</entry>
<entry>2010 ZONAL AVE, Los Angeles</entry>
<entry>2000 W EMPIRE AVE, Burbank</entry>
</Addresses>
The no of entry elements is dynamic.
At IVR interface, I need to iterate these entries to choose one of them
Like
Press 1 for "205 W LAUREL ST, Glendale"
Press 2 for "20261 E COVINA BLVD, Charter Oak"
Press 3 for
....
I have looked into foreach tag, but how do I keep track of the count 1, 2, 3...
Please advise.
We've Moved! Please visit our new and improved forum over at our new portal: https://portal.plumvoice.com/hc/en-us/community/topics
Iterating through an xml with prompts
Re: Iterating through an xml with prompts
You will have to use another programming language, like PHP, to dynamically generate menus. You should POST the XML to a .PHP page using the <submit> tag. Then you must parse your XML and generate VXML grammar and prompts. You can echo those out via PHP. Here is an example:
Code: Select all
<?php
$addresses = $_POST['address_xml']; // Get addresses XML from POST
// Do some string manipulation here on the XML to make $addresses an array of your addresses
$address_grammar =
'<grammar type="application/srgs+xml" root="addresses" mode="dtmf">
<rule id="addresses">
<one-of>';
$address_prompt = '';
// Loop for each address to add to $address_grammar and $address_prompt
foreach ($addresses as $i => $address) {
// Add grammar info
$address_grammar .= '<item>' . $i+1 . '<tag>address="' . $address . '"</tag>';
// Add to address prompt
$address_prompt .= 'Press ' . $i+1 . ' for ' . $address;
}
$address_grammar .= '</one-of></rule></grammar>';
header('Content-type: text/xml');
?>
<?xml version="1.0"?>
<vxml version="2.0">
<form id="get_address">
<field name="address">
<?= $address_grammar ?>
<prompt> <?= $address_prompt ?> </prompt>
<filled>...</filled>
</field>
</form>
</vxml>
Plum Support
http://www.plumvoice.com
http://www.plumvoice.com