<data>

<data>

The <data> element allows a VoiceXML application to fetch arbitrary XML data from a document server without transitioning to a new VoiceXML document. The XML data fetched by the <data> element is bound to ECMAScript through the named variable that exposes a read-only subset of the W3C Document Object Model (DOM).

Attributes

Name
Data type
Description

src

String

The URI specifying the location of the XML data to retrieve.

name

String

srcexpr

String

Like src, except that the URI is dynamically determined by evaluating the given ECMAScript expression when the data needs to be fetched. If srcexpr cannot be evaluated, an error.semantic event is thrown.

method

String

(defaults to “get”) The request method: "get", "post", or "raw".

namelist

String

The list of variables to submit. The default is to submit no variables. If a namelist is supplied, it may contain individual variable references that are submitted with the same qualification used in the namelist. Declared VoiceXML and ECMAScript variables can be referenced.

enctype

String

(defaults to “application/x-www-form-urlencoded”) This attribute specifies the HTTP POST encoding format. The other permissible choices are “multipart/form-data”, which is the encoding method used by the platform when binary data is being submitted, “application/xml”, when submitting raw XML, and “application/json”, when submitting raw JSON.

rawexpr

String

The raw XML or JSON string to submit to the URI. You can only use this attribute when using the “raw” method and either the “application/xml” or “application/json” enctype.

accept

String

Specifies what the platform should accept as the data tag response. By default it will treat all responses as “text/xml”, but it can also be overridden to accept “application/json”. This attribute will also send an “Accept” header with the given value.

headers

String

Inserts additional HTTP headers in the request. The value passed into this parameter must be a JSON string of key / value pairs. For example {“x-custom-header-a”:“asdf”} would be converted into the header “x-custom-header-a: asdf”

headersexpr

String

An ECMAScript expression yielding the headers data.

fetchaudio

String

(defaults to “fetchaudio” global property value) The URI of the audio clip to play while the fetch is being done.

fetchhint

This attribute is not supported.

fetchtimeout

String

(defaults to “fetchtimeout” global property value) The timeout for fetches. Must be specified with the appropriate time units (e.g., “120s” for 120 seconds).

maxage

String

(defaults to “documentmaxage” global property value) Tells the platform the maximum acceptable age, in seconds, of cached documents.

maxstale

String

(defaults to “documentmaxstale” global property value) Tells the platform the maximum acceptable staleness, in seconds, of expired cached documents.

Notes

Exactly one of “src” and “srcexpr” must be specified. Please refer to the VoiceXML 2.1 Draft for examples and detailed usage information for this tag. NOTE: When setting the “method” attribute to “post”, the platform does a normal POST with the variables passed in the namelist encoded as “application/x-www-form-urlencoded” or “multipart/form-data”. After encoding the namelist, the platform passes the data and tells the server that the data is encoded with whatever format it used to encode. However, when setting the “method” attribute to “raw”, the “raw” type is still a POST request, but does two things to change the default behavior, allowing control over both the data and the encoding type reported to the server: 1) Rather than encoding the namelist to create the “data”, the platform instead executes the rawexpr javascript expression and uses the result for the data. 2) It passes the encoding that was provided in the “enctype” attribute as the encoding to the web server.

Both headers and headersexpr adhere to standard web browser conventions for where overriding certain headers is forbidden for security purposes: https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name

XML Example

<?xml version="1.0"?>
<vxml version="2.1">
  <form>
    <data name="domstuff" src="datatag.xml"/>
    <block>
      Hello <value expr="domstuff.documentElement.firstChild.toString()"/>.
    </block>
  </form>
</vxml>

The output of the above script would be:

Computer: Hello World.

JSON Example

Here we tell the platform to accept “application/json” type responses from “json.php”.

<?xml version="1.0"?>
<vxml version="2.1">
  <form>
    <var name="account_number" expr="112233" />
    <data name="test" src="json.php" accept="application/json" namelist="account_number" method="post" />
    <block>
      <prompt>
        Hello <value expr="test.first_name" /> <value expr="test.last_name" />.
        Your account number is <say-as type="digits"><value expr="test.account_number" /></say-as>
      </prompt>
    </block>
  </form>
</vxml>

The output of the above script would be:

Computer: Hello John Smith. Your account number is 1 1 2 2 3 3.

Child Tags

None

Parent Tags

<block>, <catch>, <error>, <filled>, <foreach>, <form>, <help>, <if>, <noinput>, <nomatch>, <vxml>

Last updated