Home > Articles > Web Services > XML

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

3.49 script

Element type



charset | fetchhint | fetchtimeout | maxage (2.0) | maxstale (2.0) | src


block | catch | error | filled | form | help | if | menu | noinput | nomatch | vxml




Instructs the interpreter to execute the contents of this element or the external script it refers to using the ECMAScript interpreter that manages the other VoiceXML variables.


<!ELEMENT script (#PCDATA) >
<!ATTLIST script
  src           %uri; #IMPLIED
  charset       CDATA #IMPLIED
  %cache.attrs; >

Language model


  • charset : CDATA

    Indicates the character encoding of the external resource if the src attribute is used.

  • fetchhint : (prefetch | safe)

    Indicates whether the interpreter may prefetch the destination document specified by this element's next attribute. A value of prefetch indicates the resource may be retrieved at the time the containing VoiceXML document is retrieved. A value of safe indicates that the resource specified by this element should not be prefetched, but should instead be retrieved at the time that the interpreter executes this element.

  • fetchtimeout : duration

    The interval to wait for the content to be returned before throwing an error.badfetch event. If this attribute is not specified, the interpreter derives a value from the most locally scoped fetchtimeout property.

  • maxage : integer

    Indicates the maximum allowable age of the fetched document in seconds. If the cached copy is older than the specified maxage, a new copy will be fetched when the interpreter executes this element. If this attribute is not specified, the interpreter derives a value from the most locally scoped maxage property. If no maxstale attribute is defined and it is impossible to fetch a new copy on the content the interpreter will throw an error.badfetch instead of using stale content.

  • maxstale : integer

    Indicates that the interpreter may use stale content for this element as long as its age is no older than maxage plus the value of maxstale in seconds. If this attribute is not specified, the interpreter derives a value from the most locally scoped maxstale property.

  • src : uri

    Indicates that the body of this script element is stored at the given URI.


CDATA containing ECMAScript code.


Example 3-60 Various applications of the script element

<vxml version="2.0">
  <var name="taxrate" expr=".0825"/>

  <!-- A simple script for computing the tax rate -->
function computeTax(valInCents){
  return taxrate * valInCents;

  <!-- A JSP that returns the cartInfo variable in the form of 
  ECMAScript assignments -->
  <script src="GetCartInfo.jsp"/>

  <form id="completesale">
      <prompt>Your subtotal is 
        <value expr="cartInfo.subTotal"/>.</prompt>

    <field name="expressmail" type="boolean">
      <prompt>Would you like to ship this using express mail 
        for an additional 
        <say-as type="currency">
          <value expr="computeShipping(cartInfo.weight)"/>?

      <var name="total"/>
total = cartInfo.subTotal + computeTax(cartInfo.subTotal) + 
      <prompt>Your total comes to <value expr="total"/>.</prompt>

Example 3-60 demonstrates how to use the script element to define inline ECMAScript processing as well as referencing ECMAScript stored externally - in this case generated from a JSP. You'll notice that the variables declared from VoiceXML (e.g. form field variables or variables declared using the var element) are accessible to the ECMAScript code.

  • + Share This
  • 🔖 Save To Your Account