Plum DEV Documentation
developer_reference:dataexchange

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
developer_reference:dataexchange [2015/07/31 14:08]
admin [Data Exchange]
developer_reference:dataexchange [2017/02/09 11:24] (current)
admin
Line 102: Line 102:
       The grass is <value expr="​random.stuff1"/>​.       The grass is <value expr="​random.stuff1"/>​.
       The sky is <value expr="​random.stuff2"/>​.       The sky is <value expr="​random.stuff2"/>​.
-      The stream ​is <value expr="​random.stuff3"/>​.+      The sun is <value expr="​random.stuff3"/>​.
     </​block>​     </​block>​
   </​form>​   </​form>​
Line 135: Line 135:
 The grass is green. \\ The grass is green. \\
 The sky is blue. \\ The sky is blue. \\
-The stream ​is yellow.+The sun is yellow.
  
 ==== Using the Data Tag ==== ==== Using the Data Tag ====
  
-The <​data>​ tag is also like a function call executed by a GET or POST. It differs from the <​subdialog>​ tag in that it does not execute a remote VoiceXML document, but instead expects the remote application to return an XML result. The <​data>​ tag sends document level variables to your application server script, which generates an XML file to be returned to Plum DEV. This XML file is then mapped directly into an ECMAScript DOM object for Plum DEV to reference as a variable. ​+The <​data>​ tag is also like a function call executed by a GET or POST. It differs from the <​subdialog>​ tag in that it does not execute a remote VoiceXML document, but instead expects the remote application to return an XML or JSON result. The <​data>​ tag sends document level variables to your application server script, which generates an XML or JSON file to be returned to Plum DEV. The file is then mapped directly into an ECMAScript DOM object ​for XML responses or just a generic ECMAScript object for JSON responses ​for Plum DEV to reference as a variable.
  
 Here is an example that demonstrates the use of the <​data>​ tag: Here is an example that demonstrates the use of the <​data>​ tag:
Line 173: Line 173:
         The sky is <value expr=         The sky is <value expr=
         "​thedata.documentElement.childNodes.item(1).firstChild.toString()"/>​.         "​thedata.documentElement.childNodes.item(1).firstChild.toString()"/>​.
-        The stream ​is <value expr=+        The sun is <value expr=
         "​thedata.documentElement.childNodes.item(2).firstChild.toString()"/>​.         "​thedata.documentElement.childNodes.item(2).firstChild.toString()"/>​.
       </​block>​       </​block>​
Line 180: Line 180:
 </​code>​ </​code>​
  
-From this example, parent.vxml can use the variables that are passed to it from data.xml. (A small note on XML: You can create and name a tag anything you want, as long as the tag is closed off properly within the XML document.) Note that data.xml is similar to subdialog.php in that both files can return the strings "​green",​ "​blue",​ and "​yellow"​ back to the VoiceXML document. Thus, the VoiceXML document would play the following:+From this example, parent.vxml can use the variables that are passed to it from data.php. (A small note on XML: You can create and name a tag anything you want, as long as the tag is closed off properly within the XML document.) Note that data.xml is similar to subdialog.php in that both files can return the strings "​green",​ "​blue",​ and "​yellow"​ back to the VoiceXML document. Thus, the VoiceXML document would play the following:
  
 The grass is green. \\ The grass is green. \\
 The sky is blue. \\ The sky is blue. \\
-The stream ​is yellow.+The sun is yellow. 
 + 
 +Here is that same example using a JSON document: 
 + 
 +<​code>​ 
 +data.php: 
 + 
 +<?php 
 +header("​Content-type:​ application/​json"​);​ 
 +$random1 = "​green";​ 
 +$random2 = "​blue";​ 
 +$random3 = "​yellow";​ 
 +echo(json_encode(array('​colors'​=>​array($random1,​ $random2, $random3))));​ 
 + 
 +<​code>​ 
 +parent.vxml:​ 
 + 
 +<?xml version="​1.0"?>​ 
 +<vxml version="​2.1">​ 
 +  <​form>​ 
 +    <data name="​thedata"​ src="​data.php"​ accept="​application/​json"/>​ 
 +      <​block>​ 
 +        The grass is <value expr="​thedata.colors[0]"/>​ 
 +        The sky is <value expr="​thedata.colors[1]"/>​ 
 +        The sun is <value expr="​thedata.colors[2]"/>​ 
 +      </​block>​ 
 +  </​form>​ 
 +</​vxml>​ 
 +</​code>​ 
  
 ==== Submit vs. Subdialog vs. Data ==== ==== Submit vs. Subdialog vs. Data ====
Line 192: Line 221:
 Other times it is easier to code the various segments as function calls using the <​subdialog>​ tag. This method makes code more reusable and further segments functionality. However, it can increase complexity within the VoiceXML code because you will need to create and process the return values of the <​subdialog>​. ​ Other times it is easier to code the various segments as function calls using the <​subdialog>​ tag. This method makes code more reusable and further segments functionality. However, it can increase complexity within the VoiceXML code because you will need to create and process the return values of the <​subdialog>​. ​
  
-Finally, sometimes you'd rather keep all call logic within the VoiceXML document and use the <​data>​ tag. This method allows you to generate completely static VoiceXML scripts and only have the application server generate basic XML documents. This approach will create the most complex VoiceXML scripts and the simplest application server code.   +Finally, sometimes you'd rather keep all call logic within the VoiceXML document and use the <​data>​ tag. This method allows you to generate completely static VoiceXML scripts and only have the application server generate basic XML or JSON documents. This approach will create the most complex VoiceXML scripts and the simplest application server code.