Experimental Extension. Fetches arbitrary XML data from an HTTP server, or submits values to a server.
<data
src="URI"
name="string"
srcexpr="js_expression"
expr="js_expression"
method="get"|"post"
namelist="variable1 ..."
enctype=MIME_type
fetchhint="prefetch"|"safe"
fetchtimeout="time_interval"
fetchaudio="URI"
maxage="time_interval"
maxstale="time_interval"
/>
The <data> tag fetches or submits data without transitioning to a new VoiceXML document.
The XML data fetched by the <data> element is returned in a read-only JavaScript variable via an object model as specified in the W3C Document Object Model (DOM), described in http://www.w3c.org/TR/DOM-Level-2-Core. Appendix E of the specification describes the JavaScript language binding for the DOM.
Note: The current BeVocal VoiceXML implementation of <data> precedes finalization of the standard to give developers the opportunity to use the tag and provide feedback, which we can pass on to the W3C. If <data> is standardized, the BeVocal VoiceXML implementation will change as necessary to match the VoiceXML standard. If such changes occur, we will attempt to maintain backwards compatibility with the current implementation.
| Attribute | Description |
src |
URI specifying the location of the XML data. Optional (as alternative to |
name |
Variable name, which must be a valid JavaScript identifier and may not be a reserved keyword in either JavaScript or Java. If the |
srcexpr |
JavaScript expression that evaluates to grammar file URI. Optional (as alternative to If you specify this attribute, the element cannot have content. You can specify either |
expr |
Extension. JavaScript expression that evaluates to grammar file URI. Optional (as alternative to Note: The If you specify this attribute, the element cannot have content. You can specify either |
method |
The query request method, either |
enctype |
MIME encoding used when submitting data with the post method. Optional (default is application/x-www-form-urlencoded multipart/form-dataThe type multipart/form-data is more efficient when submitting large amounts of binary data. |
namelist |
Space-separated list of variables to submit to the server. Optional (default is to submit no variables). This attribute can specify any variable currently in scope, both VoiceXML variables and JavaScript variables, including shadow variables and other variables that have not been explicitly declared. A variable set to a JavaScript object is submitted as the individual component values; see Submitting Complex JavaScript Objects. |
fetchhint |
Specifies whether the interpreter can attempt to optimize dialog interpretation by prefetching the resource. See Prefetching Resources. Optional. |
fetchtimeout |
Specifies the interval to wait for the resource to be returned before throwing a |
fetchaudio |
Specifies the URI of an audio clip to play while a resource is being fetched. See Background Audio. Optional. The specified audio clip is played only if the |
maxage |
Specifies the maximum acceptable age, in seconds, of the cached resource. See Maximum Age. Optional. |
maxstale |
Specifies the maximum acceptable time, in seconds, during which an expired cached resource can still be used. See Maximum Stale Time. Optional. |
If a <data> element names a variable that is already in scope, it does not declare a new variable with the same name, but simply assigns a value to the existing variable--the variable is assigned a reference to the DOM returned from the server.
(VoiceXML 1.0 only) The following attributes can be used in applications in which the version attribute of the <vxml> tag is set to 1.0.
| Attribute | Description |
caching |
VoiceXML 1.0 only. Specifies the caching policy for the resource being fetched. See Caching. Optional. Used in place of the VoiceXML 2.0 attributes |
|
|||
|
| Parents | Children |
|
<?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">
<var name="quote"/>
<var name="ticker" expr="'f'"/>
<form id="get_quote">
<block>
<data name="quote" src="quote.xml"/>
<assign name="document.quote" expr="quote.documentElement"/>
<goto next="#play_quote"/>
</block>
</form>
<form id="play_quote">
<script>
<![CDATA[
// retrieve the value contained in the node t from the DOM exposed by d
function GetData(d, t, nodata) {
try {
return d.getElementsByTagName(t).item(0).firstChild.data;
}
catch(e) {
// the value could not be retrieved, so return this instead
return nodata;
}
}
]]>
</script>
<block>
<!-- retrieve the change in the stock's value -->
<var name="change" expr="GetData(quote, 'change', 0)"/>
<!--Say the company name -->
<prompt>
The stock for <value expr="GetData(quote, 'name', 'unknown')"/> is
</prompt>
<!-- Say 'unchanged, 'up', or 'down' -->
<!-- based on zero, positive, or negative change -->
<if cond="change == 0">
<prompt> unchanged at </prompt>
<else/>
<if cond="change > 0"> <!-- Positive change -->
<prompt> up by </prompt>
<else/> <!-- Negative change -->
<prompt> down by </prompt>
</if>
<!-- Say change in value as positive number -->
<prompt>
<value expr="Math.abs(change)"/> to
</prompt>
</if>
<!-- Say the current price per share -->
<prompt> <value expr="GetData(quote, 'last', 0)"/> </prompt>
</block>
</form>
</vxml>
The data file quote.xml follows:
<?xml version="1.0" ?>
<xml>
<quote>
<ticker>F</ticker>
<name>Ford Motor Company</name>
<change>1.0</change>
<last>30.00</last>
</quote>
</xml>
| Café Home |
Developer Agreement |
Privacy Policy |
Site Map |
Terms & Conditions Part No. 520-0001-02 | © 1999-2007, BeVocal, Inc. All rights reserved | 1.877.33.VOCAL |