CCXML 1.0-W3C Development GuideHome  |  Frameset Home


<foreach>  element

Voxeo Extension Element
The <foreach> element is a Voxeo extension to the CCXML 1.0 specification, (which is being proposed for inclusion to the spec), that allows the developer to iterate through a set of array values, (such as the session.connections[] array). This allows a simpler shorthand than using pure ECMAScript to loop through array values.


usage
<foreach cond="(ECMAScript Expression)" item="(variable name)" name="(variable name)" object="(ECMAScript Expression)">


attributes
condData Type: (ECMAScript Expression)Default: Optional
The cond attribute specifies an ECMAScript expression which can be evaluated to 'true' or 'false'. A condition must evaluate to 'true' in order for any enclosed operations to be performed.


itemData Type: (variable name)Default: Optional
The item attribute denotes the name of the variable that stores a particular array value as it is being iterated within the loop. If this variable is not already defined, then it will be declared upon invocation of the <foreach> element and will evaluate to "item$".
nameData Type: (variable name)Default: Optional
The name attribute defines the name of the index that is to be refenced, (in this case, the connectionid). If undefined, this will contain a default value of "index$".
objectData Type: (ECMAScript Expression)Default: Required
The object attribute defines the name of the array or object to enumerate by the <foreach> element; failure to specify this attribute will result in an error.semantic event being thrown.




parents
none


children
none


code samples
<1.0 foreach -item-object-name> sample
<?xml version="1.0" encoding="UTF-8"?>
<ccxml version="1.0" xmlns="http://www.w3.org/2002/09/ccxml">

<eventprocessor>

  <transition event="connection.alerting">
  <accept/>
  <log expr="'*** CALL ACCEPTED ***'"/>
  </transition>

  <transition event="connection.connected">
  <!-- NOTE: CHECK THE LOGGER TO SEE THE ARRAY VALUES -->
  <foreach item="item" object="session.ioprocessors" name="name">
    <log expr="'*** IO PROCESSOR ['+name+'] = ' + item + ' ***'"/>
  </foreach>
  <exit/>
  </transition>

  <transition event="error.*">
  <log expr="'ERROR OCCURRED: '+ event$.name"/>
  <exit/>
  </transition>

</eventprocessor>

</ccxml>



additional links
none


  ANNOTATIONS: EXISTING POSTS
steve.sax
10/17/2007 8:55 PM (EDT)

For those of you who might be interested,  here are some examples of the SIP headers that you can utilize to obtain all
the information provided by our carriers that you may output using the <foreach> element:

------------------------
session.connections[connid].protocol.sip.headers['from']
------------------------

------------------------
session.connections[connid].protocol.sip.headers['via'][0]
------------------------

If would like to check out all information in the SIP headers, you can log each value using the following:

<foreach object="session.connections[connid].protocol.sip.headers">
  <log expr="'*** name$ = [' + name$ + '] AND index$= [' + item$ + ']
***'"/>
</foreach>

- Steve

login



© 2008 Voxeo Corporation  |  Voxeo IVR  |  VoiceXML & CCXML IVR Developer Site