W3C

State Chart XML (SCXML): State Machine Notation for Control Abstraction

W3C Working Draft 16 May 2008

This version:
http://www.w3.org/TR/2008/WD-scxml-20080516/
Latest version:
http://www.w3.org/TR/scxml/
Previous version:
http://www.w3.org/TR/2007/WD-scxml-20070221/
Editors:
Jim Barnett, Aspect Software (Editor-in-Chief)
Rahul Akolkar, IBM
R J Auburn, Voxeo
Michael Bodell, Microsoft
Daniel C. Burnett, Voxeo
Jerry Carter, Nuance
Scott McGlashan, HP
Torbjörn Lager, Invited Expert
Mark Helbing, (until 2006, when at Nuance)
Rafah Hosn, (until 2008, when at IBM)
T.V. Raman, (until 2005, when at IBM)
Klaus Reifenrath, (until 2006, when at Nuance)

Abstract

This document describes SCXML, or the "State Chart extensible Markup Language". SCXML provides a generic state-machine based execution environment based on CCXML and Harel State Tables.

Status of this Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.

This document is the fourth Public Working Draft of SCXML published on 16 May 2008 for review by W3C Members and other interested parties, and has been developed by the Voice Browser Working Group as part of the W3C Voice Browser Activity. The main differences from the previous draft are:

Please note that most sections have been modified because of above changes, the editors would like readers to read the whole document carefully and give comments.

Comments for this specification are welcomed to www-voice@w3.org (archives).

Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

Table of Contents

1 Terminology
2 Overview
3 Core Module
    3.1 <scxml>
        3.1.1 Attribute Details
        3.1.2 Children
    3.2 <state>
        3.2.1 Attribute Details
        3.2.2 Children
    3.3 <transition>
        3.3.1 Attribute Details
        3.3.2 Children
    3.4 <parallel>
        3.4.1 Attribute Details
        3.4.2 Children
    3.5 <initial>
        3.5.1 Attribute Details
        3.5.2 Children
    3.6 <final>
        3.6.1 Attribute Details
        3.6.2 Children
    3.7 <onentry>
        3.7.1 Attribute Details
        3.7.2 Children
    3.8 <onexit>
        3.8.1 Attribute Details
        3.8.2 Children
    3.9 <history>
        3.9.1 Attribute Details
        3.9.2 Children
    3.10 Executable Content
        3.10.1 <event>
            3.10.1.1 Attribute Details
            3.10.1.2 Children
        3.10.2 <if>
            3.10.2.1 Attribute Details
            3.10.2.2 Children
        3.10.3 <elseif>
            3.10.3.1 Overview
            3.10.3.2 Attribute Details
        3.10.4 <else>
            3.10.4.1 Overview
            3.10.4.2 Attribute Details
        3.10.5 <log>
            3.10.5.1 Overview
            3.10.5.2 Attribute Details
        3.10.6 Extensibility of Executable Content
    3.11 Referencing External Files
    3.12 SCXML Events
4 External Communications Module
    4.1 <send>
        4.1.1 Overview
        4.1.2 Attribute Details
    4.2 <invoke>
        4.2.1 Attribute Details
        4.2.2 Children
    4.3 <param>
        4.3.1 Attribute Details
        4.3.2 Children
    4.4 <finalize>
        4.4.1 Attribute Details
        4.4.2 Children
    4.5 <content>
        4.5.1 Attribute Details
        4.5.2 Children
5 Data Module
    5.1 <datamodel>
        5.1.1 Attribute Details
        5.1.2 Children
    5.2 <data>
        5.2.1 Attribute Details
        5.2.2 Children
    5.3 <assign>
        5.3.1 Attribute Details
        5.3.2 Children
    5.4 <validate>
        5.4.1 Attribute Details
        5.4.2 Children
    5.5 System Variables
6 Script Module
    6.1 <script>
        6.1.1 Attribute Details
        6.1.2 Children
7 Anchor Module
    7.1 <anchor>
        7.1.1 Attribute Details
        7.1.2 Children
8 Expressions
    8.1 Conditional Expressions
    8.2 Location Expressions
    8.3 Legal Data Values and Value Expressions
    8.4 Errors in Expressions
9 Profiles
    9.1 The Minimal Profile
        9.1.1 Conformance
        9.1.2 Core Module Requirements
            9.1.2.1 Conditional Expressions
    9.2 The ECMAScript Profile
        9.2.1 Conformance
        9.2.2 Core Module Requirements
            9.2.2.1 Conditional Expressions
        9.2.3 Data Module Requirements
            9.2.3.1 Location Expressions
            9.2.3.2 Value Expressions
            9.2.3.3 System Variables
        9.2.4 Script Module Requirements
        9.2.5 Additional Requirements
            9.2.5.1 The In() predicate
        9.2.6 Examples
    9.3 The XPath Profile
        9.3.1 Conformance
        9.3.2 Core Module Requirements
            9.3.2.1 Conditional Expressions
        9.3.3 Data Module Requirements
            9.3.3.1 Location Expressions
            9.3.3.2 Value Expressions
            9.3.3.3 System Variables
        9.3.4 Additional Requirements
            9.3.4.1 The In() predicate
            9.3.4.2 The instance() function
        9.3.5 Examples
10 Related Work

Appendices

A Open Issues
    A.1 Event Processors
    A.2 Alternative Notation
    A.3 parallel transition order
    A.4 error handling
    A.5 do we need <returndata>
B Algorithm for SCXML Interpretation
    B.1 Semantics of <anchor>
C Probabilistic State Machines
D Schemas
    D.1 Utility Schemas
    D.2 Schema for Core Module
    D.3 Schema for External Module
    D.4 Schema for Data Module
    D.5 Schema for Script Module
    D.6 Anchor Module Schema
    D.7 Minimal Profile Schema
    D.8 ECMAScript Profile Schema
    D.9 XPath Profile Schema
E Examples
    E.1 Language Overview
    E.2 Shale Example
    E.3 Examples of Invoke and finalize
    E.4 Custom Action Elements
F Conformance
G References


1 Terminology

[Definition: The key words must, must not, required, shall, shall not, should, should not, recommended, may, and optional in this specification are to be interpreted as described in [IETF RFC 2119].]

The terms base URI and relative URI are used in this specification as they are defined in [IETF RFC 2396].

2 Overview

This document outlines State Chart XML (SCXML), which is a general-purpose event-based state machine language that can be used in many ways, including:

SCXML combines concepts from CCXML and Harel State Tables. CCXML [W3C CCXML 1.0] is an event-based state machine language designed to support call control features in Voice Applications (specifically including VoiceXML but not limited to it). The CCXML 1.0 specification defines both a state machine and event handing syntax and a standardized set of call control elements. Harel State Tables are a state machine notation that was developed by the mathematician David Harel [Harel and Politi] and is included in UML [UML 2.0]. They offer a clean and well-thought out semantics for sophisticated constructs such as a parallel states. They have been defined as a graphical specification language, however, and hence do not have an XML representation. The goal of this document is to combine Harel semantics with an XML syntax that is a logical extension of CCXML's state and event notation.

3 Core Module

The Core Module contains the elements that define the basic Harel state machine. The Core Module can be used by itself (see 9.1 The Minimal Profile), but it will not be able to communicate with external entities or maintain an internal data model. The schema for the core module can be found at D.2 Schema for Core Module.

3.1 <scxml>

The top-level root state, which carries version information etc.

3.1.1 Attribute Details

Name Required Attribute Constraints Type Default Value Valid Values Description
initial false IDREFS none The IDs of one or more state or parallel elements contained in this state machine The id of the initial state(s) for the document. This attribute is shorthand for an <initial> child with a transition containing an unconditional transition.
name false NMTOKEN none Any valid NMTOKEN The name of this state machine. It is for purely informational purposes.
xmlns false URI none If specified, the value must be "http://www.w3.org/2005/07/scxml".
version true decimal none The only legal value is "1.0"
profile false NMTOKEN none "minimum", "ecmascript", "xpath" or other platform-defined values. The SCXML profile that this document requires. "min" denotes the Minimal Profile, "ecma" the ECMAScript Profile, and "xpath" the XPath Profile, as defined in 9 Profiles.
exmode false NMTOKEN "lax" "lax" or "strict" The execution mode of the interpreter. This defines how the interpreter should behave if it encounters an element or attribute that it does not understand. If exmode is "lax", the interpreter will silently ignore element or attribute. If exmode is "strict", the interpreter still not process the element or attribute, but will also raise the error error.unsupportedelement.

3.1.2 Children

  • <initial> An optional child which identifies the initial state for the state machine. The state machine will take the transition contained in this element as the last step in document initialization. Occurs zero or one times. See 3.5 <initial>

  • <state> A compound or atomic state. Occurs zero or more times. See 3.2 <state> for details.

  • <parallel> A parallel state. Occurs zero or more times. See 3.4 <parallel> for details.

  • <final> A top-level final state in the state machine. Occurs zero or more times. When the state machine reaches a top-level final state (i.e., one that is an immediate child of <scxml>), it has finished processing and will terminate. See 3.6 <final> for details.

A state machine must specify either an "initial" attribute or an <initial> element, but not both. Either notation can be used to specify the state that the machine will transition to at the start of processing. The only difference between the two notations is that the <initial> element contains a <transition> element which may in turn contain executable content which will be executed before the initial state is entered. If the "initial" attribute is specified instead, the specified state will be entered, but no executable content will be executed.

3.2 <state>

Holds the representation of a state.

3.2.1 Attribute Details

Name Required Attribute Constraints Type Default Value Valid Values Description
id true ID none A valid id as defined in [XML Schema] The identifier for this state. It MUST be unique within the document.
src false URI none Any URI URI of a file containing material to be inserted into this state. See 3.11 Referencing External Files for details.
initial false IDREFS none The IDs of one or more state or parallel elements contained in this state. The id of the default initial state for this state. This attribute is shorthand for an <initial> child containing an unconditional transition.

3.2.2 Children

  • <onentry> Optional element holding executable content to be run upon entering this <state>. Occurs 0 or 1 times. See 3.10 Executable Content

  • <onexit> Optional element holding executable content to be run when exiting this <state>. Occurs 0 or 1 times. See 3.10 Executable Content

  • <transition> Defines an outgoing transition from this state. Occurs 0 or more times. See 3.3 <transition>

  • <initial> In states that have substates, an optional child which identifies the default initial state. Any transition which takes the parent state as its target will result in the statemachine also taking the transition contained inside the <initial> element. See 3.5 <initial>

  • <state> Defines a sequential substate of the parent state. Occurs 0 or more times.

  • <parallel> Defines a parallel substate. Occurs 0 or more times. See 3.4 <parallel>

  • <final>. Defines a final substate. Occurs 0 or more times. When the state machine enters a final substate, an event "ParentID.done" is generated, where 'ParentID' is the ID of the final state's parent state. This event indicates that the parent state has reached completion. See 3.6 <final>.

  • <history> A child which represents the descendant state that the parent state was in the last time the system transitioned from the parent. A transition with this state as its target is in fact a transition to one of the other descendant states of the parent. May occur 0 or more times. See 3.9 <history>.

A complex state, namely one that has <state> or <parallel> children, must specify either an "initial" attribute or am <initial> element, but not both. Either notation can be used to specify the state's default initial state. See 3.5 <initial> for a discussion of the difference between the two notations.

3.3 <transition>

Transitions between states are triggered by events and conditionalized via guard-conditions. The optional attribute "target" specifies the destination of the transition, which may be a <state> or a <parallel> region. If the "target" on a <transition> is omitted, then taking the transition has the effect of leaving the machine in the same state after invoking any executable content that is included in the transition. Such a transition is equivalent to an 'event' handler in Harel State Table notation. Note that this is different from a <transition> whose "target" is its source state. In the latter case, the state is exited and reentered, triggering execution of its <onentry> and <onexit> executable content.

Any executable content contained in a transition is executed after the <onexit> handlers of the source state and before the <onentry> handlers of the target state.

3.3.1 Attribute Details

Name Required Attribute Constraints Type Default Value Valid Values Description
event false NMTOKEN none Any event name. The wildcard '*' is permitted. See 3.12 SCXML Events for details. The event trigger for this transition. The transition will be taken only when the event is generated. See B Algorithm for SCXML Interpretation for details on how transitions are selected.
cond false Boolean expression none Any boolean expression. Guard condition for this transition. If it is present, the transition is taken only if the guard condition evaluates to true. See 8.1 Conditional Expressions for details.
target false IDREFS none Whitespace separated list of state IDs in the current state machine. If multiple states are specified all must be descendants of the same <parallel> element. The identifier(s) of the state or parallel region to transition to.
anchor false NMTOKEN none Any anchor type The type of the anchor to transition to. See 7.1 <anchor> for details.

Only one of "target" and "anchor" may be specified.

3.3.2 Children

  • Immediate children of <transition> above are executable content that is run after the <onexit> handler for this state and before the <onentry> handler in the target state. See 3.10 Executable Content

If a transition has both "event" and "cond" attributes, it will be taken only if an event is raised that matches the "event" pattern and the "cond" condition evaluates to true. If the "event" clause is missing, the transition is taken whenever the "cond" evaluates to true. If the "cond" clause is also empty, the transition is taken as soon as the state is entered. Note that the data model can be changed only by the execution of <invoke> or executable content. Therefore transitions with empty "event" conditions need be checked only 1) upon arrival into a state, after the completion of all <onentry> handlers and 2) after an event has been processed (since it may have triggered executable content which could have updated the data model). See B Algorithm for SCXML Interpretation for details.

3.4 <parallel>

A state that encapsulates a set of parallel states. The <parallel> element has <onentry> and <onexit> and <transition> elements analogous to <state>. In addition, the <parallel> element holds a set of <state> elements that execute in parallel and join at the <onexit> handler of the <parallel> element. In particular, when all of the parallel substates reach final states, a completion event "ID.done" is generated, where "ID" is the "id" of the <parallel> element. Either the <parallel> element or one of its ancestors can trigger a transition off this event, at which time the <onexit> handler of the element will be executed.

When the state machine enters the parent <parallel> state, it simultaneously enters each child state. Transitions within the individual child elements operate normally. However any of the child elements may take a transition outside the <parallel> element. When this happens, the <parallel> element and all of its child elements are exited and the corresponding <onexit> handlers are executed. The handlers for the child elements execute first, in document order, followed by those of the parent <parallel> element, followed by an action expression in the <transition> element, and then the <onentry> handlers in the "target" state. See B Algorithm for SCXML Interpretation for a detailed description of the semantics <parallel> and the rest of SCXML.

3.4.1 Attribute Details

Name Required Attribute Constraints Type Default Value Valid Values Description
id true ID none A valid id as defined in [XML Schema] The identifier for this state. It MUST be unique within the document.
src false URI none Any URI URI of a file containing material to be inserted into this state. See 3.11 Referencing External Files for details.

3.4.2 Children

  • <onentry> Holds executable content to be run upon entering the <parallel> element. Occurs 0 or one times. See 3.10 Executable Content

  • <onexit> Holds executable content to be run when exiting this element. Occurs 0 or one times. See 3.10 Executable Content

  • <transition> Defines an outgoing transition from this state. Occurs 0 or more times. See 3.3 <transition>

  • <state> Defines a parallel substate region. Occurs 0 or more times.

  • <parallel> Defines a nested set of parallel regions. Occurs 0 or more times.

  • <history> A child which represents the state configuration that this state was in the last time the system transitioned from it. A transition with this history pseudo-state as its target is in fact a transition to the set of descendant states that were active the last time this state was exited. Occurs 0 or more times. See 3.9 <history>.

3.5 <initial>

This element represents the default initial state for a complex state with sequential substates. Suppose <state> S1 has child states S11, S12, and S13. If the system is in S1, it must also be in one (and only one) of S11, S12, or S13. A <transition> in a distinct <state> S2 may take S11, S12, or S13 as its "target", but it may also simply specify the parent S1. In that case, the <initial> child of S1 specifies which of S11, S12, or S13 the system should transition to.

The only difference between the <initial> element and the 'initial' attribute is that the <initial> element contains a <transition> element which may in turn contain executable content which will be executed before the default state is entered. If the "initial" attribute is specified instead, the specified state will be entered, but no executable content will be executed. As an example, suppose that parent state S contains child states S1 and S2. If S specifies S1 as its default initial state via the "initial" attribute, then any transition that specifies S as its target will result in S entering S1 as well as S. In this case, the result is exactly the same as if the transition had taken S1 as its target. If, on the other hand, S specifies S1 as its default initial state via the <initial> tag containing a <transition> with S1 as its target, the <transition> can contain executable content which will execute before the default entry into S1. In this case, there is a difference between a transition that takes S as its target and one that takes S1 as its target. In the former case, but not in the latter, the executable content inside the <initial> transition will be executed.

3.5.1 Attribute Details

None

3.5.2 Children

  • <transition> A conditionless transition (i.e., one without a "cond" or "event" attribute). Such a transition is always enabled and will be taken as soon as the state is entered. The "target" of the transition must be a descendant of the <initial> element's parent <state>.

3.6 <final>

<final> represents a final state of a compound state. When the system reaches a final state, it means that its parent state has completed its activity. Upon entry to the final state, the event "ParentID.done" is generated, where 'ParentID' is the ID of the parent state. Note that even though the parent state has run to completion, more remote ancestors may still be active. When the state machine reaches a top-level final state (namely one that is a child of <scxml>), it has finished processing and will terminate.

3.6.1 Attribute Details

Name Required Attribute Constraints Type Default Value Valid Values Description
id true ID none A valid id as defined in [XML Schema] The identifier for this state. It MUST be unique within the document.

3.6.2 Children

  • <onentry> Optional element holding executable content to be run upon entering this state. Occurs 0 or 1 times. See 3.10 Executable Content

  • <onexit> Optional element holding executable content to be run when exiting this state. Occurs 0 or 1 times. See 3.10 Executable Content

3.7 <onentry>

3.7.1 Attribute Details

None.

3.7.2 Children

The children of the <onentry> handler consist of executable content as defined in 3.10 Executable Content

3.8 <onexit>

3.8.1 Attribute Details

None.

3.8.2 Children

The children of the <onexit> handler consist of executable content as defined in 3.10 Executable Content

3.9 <history>

The <history> pseudo-state allows for 'pause and resume' control flow. Whenever a complex <state> is exited, its <history> pseudo-state, if present, records the state configuration at exit. Later a <transition> taking the <history> state as its "target" allows the <state> to pick up where it left off. If the state containing the <history> state is a compound state, then the history value will be a single state. However, if the parent state is a <parallel> state, the history value will be a set of states, one for each parallel child region.

3.9.1 Attribute Details

Name Required Attribute Constraints Type Default Value Valid Values Description
id true ID none A valid id as defined in [XML Schema] Identifier for this pseudo-state. It MUST be unique within the document.
type false NMTOKEN shallow "deep" or "shallow" If the value is 'shallow' then this state records only the immediate children of the parent <state>. In this case a <transition> with the history pseudo-state as its "target" will end up in the immediate child state that the parent was in the last time it was exited. On the other hand, if this attribute is set to 'deep', the history pseudo-state will remember nested states. In this case a <transition> with the history pseudo-state as its "target" will end up in the most deeply nested descendant <state> the parent was in the last time it was exited.

3.9.2 Children

  • <transition> A conditionless transition (i.e., one without a "cond" or "event"; attribute). Such a transition is always enabled and may be taken as soon as the state is entered. This <transition> represents the default history state and indicates the <state> to transition to if the parent <state> has never been entered before. if "type" is 'shallow', then the "target" of this <transition> must be an immediate child of the parent <state>. Otherwise it can be any descendant <state>. If the parent of the <history> state is a <parallel> state, then this transition may take multiple targets (each much be in a distinct parallel child state).

3.10 Executable Content

Executable content consists of actions that are performed as part of taking transitions and entering and leaving states (<onentry> and <onexit>, etc.) Executable content occurs in blocks, meaning that wherever executable content may occur, an arbitrary number of elements may occur. These elements in a block are processed in document order. If the processing of an element causes an error to be raised, the remaining elements of the block are not processed and the error event is placed on the internal event queue and processed like any other event (see B Algorithm for SCXML Interpretation). In particular, the error event will not be removed from the queue and processed until all events preceding it in the queue have been processed.

Note that 4 External Communications Module, 5 Data Module and 6 Script Module all define additional elements of executable content beyond those listed here. Thus the exact set of executable content available depends on the profile (see 9 Profiles for examples).

3.10.1 <event>

The <event> element may be used to raise an event in the current SCXML session. The event will be added to the session's internal event queue, but will not be processed until later, following the algorithm specified in B Algorithm for SCXML Interpretation. Note in particular that the event cannot be processed until all current executable content has been executed. For example, if the <event> element occurs in the the <onentry> handlers of a state, at the very least the event will not be processed until all the executable content in the <onentry> handler has completed.

3.10.1.1 Attribute Details
Name Required Attribute Constraints Type Default Value Valid Values Description
name true NMTOKEN none Specifies the name of the event. This will be matched against the 'event' attribute of transitions.
3.10.1.2 Children

None.

3.10.2 <if>

<if> is a container for conditionally executed elements. <elseif> and <else> can optionally appear within an <if> as immediate children, and serve to partition the elements within the <if>. <else> and <elseif> have no content. <else/> is equivalent to an <elseif > element whose "cond" always evaluates to true.<else> must occur after all <elseif> tags.

Each partition within an <if> is preceded by an element having a "cond" attribute. The initial partition is preceded by the <if> and subsequent partitions by <elseif>s (or <else>). The first partition in document order with a "cond" that evaluates to true is selected. <else> always evaluates to true. A partition MAY be empty.

If an <if> has no immediate <elseif> or <else> children, the full contents of the <if> will be selected when the "cond" attribute evaluates to true.

<else> was chosen to match similar concepts in other languages, and supports examples such as

<if cond="cond1">
  <!-- selected when "cond1" is true -->
<elseif cond="cond2"/>
  <!-- selected when "cond1" is false and "cond2" is true -->
<elseif cond="cond3"/>
  <!-- selected when "cond1" and "cond2" are false and "cond3" is true -->
<else/>
  <!-- selected when "cond1", "cond2", and "cond3" are false -->
</if>
            
3.10.2.1 Attribute Details
Name Required Attribute Constraints Type Default Value Valid Values Description
cond true Conditional expression none A valid conditional expression A boolean expression. See 8.1 Conditional Expressions for details.
3.10.2.2 Children

3.10.3 <elseif>

3.10.3.1 Overview

An <elseif> partitions the content of an <if>, and provides a condition that determines the selection of the partition it begins. The executable content following the <elseif> will be executed if the <elseif>'s "cond" evaluates to true and all preceding "cond"s evaluate to false.

3.10.3.2 Attribute Details
Name Required Attribute Constraints Type Default Value Valid Values Description
cond true Conditional expression none A valid conditional expression An boolean expression. See 8.1 Conditional Expressions for details.

3.10.4 <else>

3.10.4.1 Overview

<else> is equivalent to an <elseif/> with a "cond" that always evaluates to true. Thus the executable content in an <else>'s partition will be executed if and only if all preceding "cond"s evaluate to false. <else> must occur after all <elseif> partitions.

3.10.4.2 Attribute Details

None. <else> is a synonym for <elseif cond="true">.

3.10.5 <log>

3.10.5.1 Overview

<log> allows an application to generate a logging or debug message which a developer can use to help in application development or post-execution analysis of application performance. The manner in which the message is displayed or logged is platform-dependent. The usage of label is platform-dependent. The use of <log> MUST have no other side-effects on interpretation. <log>is an empty element.

3.10.5.2 Attribute Details
Name Required Attribute Constraints Type Default Value Valid Values Description
label false string none A character string which may be used to indicate the purpose of the log.
expr true Value expression none An expression returning the value to be logged. See 8.3 Legal Data Values and Value Expressions for details. The nature of the logging mechanism is implementation-dependent, so the platform may convert this value to a convenient format before logging it.
level false positiveInteger 1 This information will be logged only if the system's log level is at this level or higher. The mechanism for specifying the log level and its legal values will be specified in a future version of this document.

3.10.6 Extensibility of Executable Content

The content presented in this specification represents a flexible, powerful, minimum set that all applications can rely on. Platforms are free to provide additional executable content corresponding to special features of their implementations. The functionality of such platform-specific content is not restricted, except that it may not cause transitions or any form of change of state, except indirectly, by raising events that are then caught by transitions. It is important to remember that SCXML treats executable content as a single blocking atomic operation and that no events are processed until all executable content has completed. For example, upon entering a state, the SCXML processor will not process any events or take any transitions until all <onentry> handlers have finished. Thus all executable content, including platform-specific extensions, SHOULD complete quickly under all circumstances. A general method for implementing extensions using the <send> element is presented in E.4 Custom Action Elements below.

Platform-specific extensions to executable content SHOULD be defined in a separate namespace, not in the 'scxml' namespace. Note that the schema D Schemas allows elements from arbitrary namespaces inside blocks of executable content. The following example shows the incorporation of CCXML functionality (see [W3C CCXML 1.0]) into SCXML. In particular an <accept> element in the 'ccxml' namespace is invoked as executable content inside a transition.

<transition event="ccxml:connection.alerting">
  <ccxml:accept connectionid="eventdata.connectionid"/>
</transition>

This markup is legal on any SCXML interpreter, but the interpretation of the <accept> element is platform-dependent. Platforms that do not support the element will either ignore it or signal an error, depending on the value of the 'exmode' attribute on the <scxml> element (see 3.1.1 Attribute Details).

3.11 Referencing External Files

The "src" attribute on <state> and <parallel> contains a URL which is used to reference an external file containing all or part of the definition of the state. The file must contain a document that matches the SCXML schema but it need not match the extra-schematic constraints contained in this specification. (For example, the document may contain transitions that reference state IDs that are not defined within it.) The exact treatment of the file depends on the format of the URL. If it ends with '#' followed by a string, the string is taken to be the ID of an element in the file and the children of that element are inserted into the state's definition before any other material contained in the <state>. Thus the state is incorporating the definition of a state defined within the file. If, on the other hand, the URL does not contain '#', the contents of the <scxml> element are inserted into the definition of the state before any other material in the state, along with an <initial> element whose <transition> takes as its target the value of the <scxml> element's 'initial' attribute. Thus in this case the contents of the entire state machine are inserted into the definition of the state.

Suppose that the file at "someURL" looks as follows:

<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initialstate="someState">
<state id="someState">
  <transition event="foo" target="someOtherState"/>
</state>
<state id="someOtherState">
  <transition event="bar" target="finalState"/>
</state>
</scxml>

A 'src' expression referencing 'someOtherState' will result in 'someOtherState's contents being inserted into the state's definition, as shown below. The following markup:

<state id="state1" src="someURL#someOtherState">
   <transition event="state1.Done" target="yetAnotherState"/>
   <final id="finalState"/>
</state>

will expand to:

<state id="state1">
   <transition event="bar" target="finalState"/>   
   <transition event="state1.Done" target="yetOtherState"/>
   <final id="finalState"/>
</state>

On the other hand, a 'src' expression referencing the whole file will result in both 'someState' and 'someOther' state being inserted into the state's definition, along with the appropriate <initial> element. Thus

<state id="state1" src="someURL">
   <transition event="state1.Done" target="yetOtherState"/>
   <final id="finalState"/>
</state>

becomes

 
 <state id="state1">
  <initial>
    <transition target="someState"/>
  </initial>
  <state id="someState">
    <transition event="foo" target="someOtherState"/>
  </state>
  <state id="someOtherState">
    <transition event="bar" target="finalState"/>
  </state>   
  <transition event="state1.Done" target="yetOtherState"/>
  <final id="finalState"/>
</state>

File inclusion takes place at load time. Implementations are free to perform document validation by any method they choose as long as the result is logically equivalent to a single pass of validation occurring after the material from the external file has been incorporated. (Note that implementations are not required to validate the external file. All that is required is that the document resulting from the incorporation be valid.)

3.12 SCXML Events

Events are one of the basic concepts in SCXML since they drive most transitions. The internal structure of events is platform-specific as long as the following external interface is observed:

  • Events have names which are matched against the "event" attribute of transitions. These names are strings consisting of alphanumeric characters plus the character '.' which is used to segment names into tokens. The "event" attribute of a transition may end with the wildcard '.*', which will match zero or more tokens at the end of the processed event's name. Thus a transition with an "event" attribute of 'error.*' will match 'error', 'error.send', 'error.send.failed', etc. Furthermore, a transition with an "event" attribute consisting solely of '*' will match any event.

  • Events optionally contain data organized into XML trees. If data is present, it must be able to be accessed via the 'event' variable, as specified in 5.5 System Variables.

  • Events are immutable read-only data structures. Neither the browser's processing nor the user's markup may modify an event once it is placed in queue. Note that this implies that modifications to the event structure are not permitted.

There is a class of error events whose names begin with 'error.'. They may be raised by the platform, as specified in this document, or under application control. They are placed in the internal event queue and processed like any other event. In particular, they are not processed immediately if there are other events in the queueand they are ignored if no transition is found that matches them. Note however that authors can arrange for otherwise unhandled errors to cause the interpreter to exit by creating a transition with "event" attribute of 'error.*' and a target of any top-level final state (i.e. one that is a child of <scxml>). If such a transition T is placed in a state S, it will cause the state machine to terminate on any error that is raised in S or one of its substates and is not handled by another transition that is placed in a substate of S or in S and preceding T in document order.

In many applications, it is important for SCXML to receive events from external entities (for example those which it contacted with <invoke> and <send>.) Such applications should use profiles that include 4 External Communications Module.

For the most part, the set of events raised during the execution of an SCXML document is application-specific and generated under author control by use of the <event> and <send> elements. However, certain events are mandatory and generated automatically by the interpreter. In this version of the specification, in addition to error events, there is only the 'Cancel' event which is sent if the state machine leaves the containing state after executing the <invoke> element but before receiving the 'Done' event. Note that there are also mandatory events that invoked components must return to the invoking SCXML state machine. In this version of the specification, there are two such events, namely 'Done' and 'CancelResponse'. We may well change or expand this set of mandatory events in future drafts of this specification. Furthermore, it is likely that there will be distinct profiles of SCXML for specific applications, such as the Multi-modal Interaction Framework [W3C MMI] and VoiceXML 3.0. These profiles will define extensions to the core language and will likely extend the set of mandatory events with additional events appropriate to the specific application.

4 External Communications Module

[N.B. In a future draft, the contents of this section will be updated to deal with the fact that different profiles may use different data models or possibly no data model at all.]

The External Communications Module adds the capability of sending and receiving events from external entities, as well as invoking external services. Its schema can be found at D.3 Schema for External Module.

Profiles that include the External Communications module MUST:

4.1 <send>

4.1.1 Overview

<send> is used to send events and data to external systems, including external SCXML Interpreters, or to raise external events in the current SCXML session.

The target of <send> is specified using the "target" and "targettype" attributes. These attributes control how the platform should dispatch the event to its final destination.

The "target" attribute specifies the unique identifier of the event target that the system should send the event to. This can be the session ID of another SCXML session. In other cases the value of this attribute will depend on the type of the target. (For example a SIP URL for SIP-INFO messages or a HTTP URL for Web Services). If no "target" attribute is specified the default target is the current SCXML session. If the value of the "target" attribute is not supported, invalid or unreachable by the platform, the system will raise an error.send.targetunavailable event.

The "targettype" attribute describes the type of the event target and is used in conjunction with the "target" attribute to determine how to connect to the target. The default value of this attribute is 'scxml'. If the event "targettype" specified is not supported, the platform will raise an error.send.targettypeinvalid event.

A platform must support the following value for the "targettype" attribute:

Value Details
"scxml" Target is an SCXML session.

Support for HTTP POST is optional, however platforms that support it must use the following value for the "targettype" attribute:

Value Details
"basichttp" Target is a URL. Data is sent via HTTP POST

Platforms may support other types of Event I/O Processors, for example: Web-services, SIP or basic HTTP GET. However, platforms SHOULD name the targettype beginning with "x-" to signify that they are platform dependent.

Note that <event> is used to raise internal events in the current SCXML session. Thus both <send> and <event> may be used to raise events in the current session, the only difference being whether the event is added to the session's internal event queue or external event queue. This difference may produce subtle differences in timing between the two methods since external events are processed only when the internal event queue is empty. See B Algorithm for SCXML Interpretation for details.

<send> also specifies the content of the message to be sent. <send> may specify message content in one of the two following mutually exclusive ways:

  • "event" attribute with an optional "namelist";

    • The "event" attribute specifies an expression that returns the name of the event.

    • The "namelist" attribute specifies a space separated list of data model locations to be included with the message.

    <datamodel>
    <data ID="target" expr="'tel:+18005551212'"/>
    <data ID="content" expr="'http://www.example.com/mycontent.txt'"/>
    </datamodel>
       ...
    <send target="target" targettype="'x-messaging'" event="'fax.SEND'" namelist="content"/>
    
  • "xmlns" attribute with explicit inline XML content specifying the message to send. The xmlns:{namespace} defines a namespace for the inline content

    <send target="'csta://csta-server.example.com/'"
          targettype="'x-csta'"
          xmlns:csta="http://www.ecma.ch/standards/ecma-323/csta">
          <csta:MakeCall>
            <csta:callingDevice>22343</callingDevice>
            <csta:calledDirectoryNumber>18005551212</csta:calledDirectoryNumber>
          </csta:MakeCall>
    </send>
    

If an explicit namespace is provided as in the "xmlns" attribute of the <send>, this namespace can be used to validate the content of the <send>. A namespace specified on a <send> applies only to the attributes and content of the <send>. Multiple namespaces may be included in the <send> to associate message content with more than one namespace.

When an explicit namespace is specified for the <send>, the content of the <send> is parsed but can be ignored by the sending SCXML interpreter until the <send> is executed. XML namespace identifiers contained in the <send> must be preserved and it is the responsibility of the platform to parse the incoming message and remove the namespace prefix, if required by the <send> target.

The sending SCXML Interpreter MUST not alter the content of the <send> and must send all the data contained within the message to the destination specified in the target attribute of <send>.

If the "targettype" specified in the <send> is not supported, the platform will raise an error event send.failed.targettypenotsupported.stateID.sendID, where 'stateID' is the "id" of the <state> containing the <send>, and 'sendID' is the automatically generated ID for this instance of <send>. If no "sendID" is specified in the <send> element, this part of the event name will be omitted. If the "targettype" is valid, but the platform is still unable to send the message for other reasons, the platform will raise an error event send.failed.targetnotfound.stateID.sendID, where 'stateID' and 'sendID' have the same significance as in the targettypenotsupported event. In the case of <send> elements with a "delay" attribute, these errors will be raised when the delay interval has passed and the platform actually attempts to send the event. Note that the absence of any error events does not mean that the event was successfully delivered to its target, but only that the platform was able to dispatch the event.

4.1.2 Attribute Details

Name Required Attribute Constraints Type Default Value Valid Values Description
event false This attribute may not be specified in conjunction with inline content Value expression none A value expression which returns a character string that indicates the type of event being generated. See 8.3 Legal Data Values and Value Expressions for details. The event type may include alphanumeric characters and the "." (dot) character. The first character may not be a dot or a digit. Event type names are case-insensitive. If neither the event attribute or in-line content is specified, an error.fetch event will be thrown. If used in conjunction with the inline content, an error.fetch will be thrown.
target false Value expression none A valid target URL A value expression returning a unique identifier of the event target that the platform should send the event to. See 8.3 Legal Data Values and Value Expressions for details.
targettype false Value expression 'scxml' scxml basichttp A value expression which returns a character string that specifies the type of the event target. See 8.3 Legal Data Values and Value Expressions for details. Values defined by the specification are:
  • scxml

  • basichttp

sendid false Location expression none Any valid location expression Any data model expression evaluating to a data model location. See 8.2 Location Expressions for details. The location's value will be set to an internally generated unique string identifier to be associated with the event being sent. If this attribute is not specified, the event identifier is dropped.
delay false Value expression '0s' A value expression which returns a time designation as defined in CSS2 [CSS2] format The character string returned is interpreted as a time interval. The send tag will return immediately, but the event is not dispatched until the delay interval elapses. Timers are useful for a wide variety of programming tasks, and can be implemented using this attribute. Note: The queue for sending events is maintained locally. Any events waiting to be sent will be purged when the session that issued this request terminates.
xmlns:[YourNameSpacePrefix] false string none This returns a namespace identifying the contained message format. More than one xmlns attribute may be included.
namelist false This attribute may not be specified in conjunction with inline content List of location expressions none List of data model locations A list of zero or more data model locations to be included with the event. See 8.2 Location Expressions for details. If used in conjunction with the inline content, an error.fetch will be thrown.
hints false Value expression none A value expression. The data returned contains information which may be used by the implementing platform to optimize message transmission. The meaning of these hints is platform-specific.

4.2 <invoke>

<invoke> and its child <finalize> are useful in states that model the behavior of an external service. The <invoke> element is executed immediately after the state's <onentry> element and sends an event invoking the external service. The <param> element may be used to pass data to the service. Any events that are received by the state machine from the invoked component during the invocation are preprocessed by the <finalize> handler before transitions are selected. The <finalize> code is used to normalize the form of the returned data and to update the data model before the transitions' "event" and "cond" clauses are evaluated.

When the <invoke> element is executed, the platform MUST start a new logical instance of the external service specified in "targettype" and pass it the data specified by "src", "srcexpr", <content>, or <param>. The service instance MAY be local or remote. In addition to the explicit arguments, the platform MUST pass a unique id to the external service . The external service MUST include the same id in all events that it returns to the invoking machine. (Syntax TBD.)

The external service MAY generate multiple events while it is processing, but it MUST generate a special ''id.Done' event , (where the 'id' is the id for this invocation) once it has finished processing. It MUST not generate any other events afterwards. If the invoking state machine takes a transition out of the state containing the <invoke> before it receives the 'Done' event, it MUST automatically send a 'Cancel' event to the invoked component to notify it that it may stop its processing. The 'Cancel' event will be sent as if it were the final <onexit> handler in the invoking state. The invoked component MUST respond to the 'Cancel' event with a 'CancelResponse' event (syntax of both events TBD). The invoking state machine will take its transition without waiting for the CancelResponse event, which will be processed like any other external event.

Note that the <invoke> element can be used to invoke an external SCXML interpreter to execute a different state machine. In this case, the external state machine acts in certain respects as if it were a set of substates of the invoking state. The behavior is thus similar to a complex state defined with <state> child elements. The most important difference is that in the <invoke> case, the external state machine does not share context or event queueswith the invoking machine. In particular, the invoked machine cannot access any variables declared in the invoking machine and data can be shared only by being explicitly passed via the <param> element. Similarly, events received or generated in one state machine are not seen by the other, though the two machines may exchange events via the <send> tag. Furthermore, state IDs need not be distinct across the two machines (though they must, of course, be distinct within each machine.) The <invoke> element thus provides a means of well-encapsulated code reuse.

When parallel states invoke the same external service concurrently, separate instances of the external service will be started. They can be distinguished by the id which is passed with the invocation. Similarly, the id contained in the events returned from the external services can be used to determine which events are responses to which invocation. Each event that is returned will be processed only by the <finalize> in the state that invoked it, but that event is then processed like any other event that the state machine receives. The finalize code can thus be thought of as a preprocessing stage that applies before the event is added to the event queue. Note that the event will be passed to all parallel states simultaneously to check for transitions.

<invoke> occurs only in atomic states, namely those that do not have <state> or <parallel> children. Thus, a state may have either <state> and <parallel> children or an <invoke> child,but not both.

4.2.1 Attribute Details

Name Required Attribute Constraints Type Default Value Valid Values Description
targettype true NMTOKEN 'scxml' 'scxml', 'vxml', 'ccxml', plus other platform-specific values. A string specifying the type of the external service. Platforms MUST support 'scxml' as a value. Platforms MAY support 'vxml2', which indicates a VoiceXML 2.x interpreter, 'vxml3' which indicates a VoiceXML 3.x interpreter, and 'ccxml', which indicates a CCXML 1.0 interpreter. Platforms MAY support additional values, but they SHOULD name the values beginning with "x-" to signify that they are platform dependent.
src false URI none Any valid URI A URL that will be passed to the external service when it is invoked. If "targettype" is one of the predefined types, the document at the URI will contain the corresponding markup to execute (i.e., an SCXML, VoiceXML, or CCXML document). In other cases, the content of the document will depend on the external service.
srcexpr false Expression None Any expression evaluating to a valid URI. A value expression that will be evaluated at the time that invoke is executed to produce the URI to pass to the external service. See 8.3 Legal Data Values and Value Expressions for details.

4.2.2 Children

  • <param>. Element containing data to be passed to the external service. Occurs 0 or more times. See 4.3 <param>.

  • <finalize>. Element containing executable content to massage the data returned from the invoked component. Occurs 0 or 1 times. See 4.4 <finalize> for details.

  • <content>. Element containing arbitrary material to be passed to the invoked component. The material may consist of non-XML markup or XML markup in any namespace. Occurs 0 or 1 times. See 4.5 <content> for details.

At most one of "src" and "srcexpr" and <content>may be specified.

<invoke> MUST not be a sibling of the <state> or <parallel> elements. It thus occurs only in atomic states, namely those which do not have substates.

4.3 <param>

4.3.1 Attribute Details

Name Required Attribute Constraints Type Default Value Valid Values Description
name true Data model expression none Valid data model path expression The name of the parameter. It will be passed unmodified to the external service. It need not specify a node in the surrounding data model.
expr false Data model expression none Valid data model expression An optional value expression (see 8.3 Legal Data Values and Value Expressions). If provided, this expression specifies the value to pass to the invoked component. Normal data model scoping rules apply as specified in 5.2 <data>.

If the "expr" attribute is missing, the "name" attribute will be taken as a data model location expression (see 8.2 Location Expressions) and the value at that location will be passed to the invoked component. If the "name" attribute does not refer to a location in the data model, an error error.illegalalloc will be generated.

4.3.2 Children

None.

4.4 <finalize>

4.4.1 Attribute Details

None.

4.4.2 Children

<finalize>'s children consist of executable content. The content will be invoked on any event that the external service returns after <invoke> has been executed. In the case of parallel states, only the finalize code in the original invoking state will be executed Within the executable content, the special variable 'event' may be used to refer to the data contained in the event which is being finalized.

If no executable content is specified, a default canonicalization handler will be invoked which will update the data model with any return values corresponding to <param> elements with missing "expr" attributes. Thus the effect of a <param> element with an empty "expr" attribute coupled with an empty <finalize> element is first to send all or part of the data model to the invoked component and then to update that part of the state machine's data model with the returned values. Note that the automatic update does not take place if the <finalize> element is absent as opposed to empty.

The purpose of the executable content is to normalize the format of data and update the data model before transitions are selected. <finalize> code may only massage data. It may not raise events or invoke external actions.

4.5 <content>

4.5.1 Attribute Details

None.

4.5.2 Children

The child elements of <content> consist of arbitrary markup which will be passed unmodified to the invoked service. The markup may consist of text, XML from any namespace, or a mixture of both.

5 Data Module

The Data Module offers the capability of storing, reading, and modifying a set of data that is internal to the state machine. Its schema may be found at D.4 Schema for Data Module . As an authoring convenience, the Data Module can read in data from an external source at load time, but at run time it is restricted to operating on its internal model. Note, however, that 4 External Communications Module allows SCXML to interact with external entities at run time, to exchange data as part of the interaction.

Profiles that include the Data Module MUST:

For examples of how to do this, see 9.2 The ECMAScript Profile and 9.3 The XPath Profile.

5.1 <datamodel>

To provide a uniform method of access to both local and remote data, we introduce a <datamodel> element which encapsulates any number of <data> elements. Each such element defines a single data object. The exact nature of the data object depends on the data model language used. The data object may be fetched from an external source or specified in-line. In cases where the data object specified is not a legal instance of the data model language, implementations MAY translate it into a legal expression, and MUST signal an error if the cannot do so.

Data created via the <data> element is local to the SCXML interpreter and not shared with any external resource. However, the local data model, or parts of it, may be sent to an external resource via the <send> element. (See 4.1 <send>.) Existing data values may be modified with the <assign> element. (See 5.3 <assign>).

Logically, there is a single globally visible data model for the entire state machine. As an authoring convenience, however, we allow <datamodel> as a child of any <state>, thus allowing parts of the data model to be distributed throughout the document closer to the locations where the data will be accessed. However, all instances of the <data> element are created and initialized when the state machine is instantiated and may be accessed from any state at any time.

5.1.1 Attribute Details

Name Required Attribute Constraints Type Default Value Valid Values Description
schema false URI none Location of the schema for this datamodel URL of the schema for this datamodel. See 5.4 <validate> for its use. This attribute may occur only on the highest-level <datamodel> element, namely the one that is a child of <scxml>. The exact nature of the schema depends on the data model language being used.

5.1.2 Children

  • <data> Occurs 0 or more times. Each instance defines a named data element.Data elements are created when the document is loaded.

5.2 <data>

The <data> element is used to declare and populate portions of the datamodel. All <data> tags are evaluated exactly once, at load time. Implementations thus MUST evaluate <data> elements at load time but MAY do so in any order they choose. Ordering dependencies among <data> elements are thus not permitted. Suppose, for example, that the declaration of element "a" precedes the declaration of element "b" in a document. It is not safe to assume that "a" will be instantiated and have a value when the declaration of "b" is executed. Therefore the "expr" in "b" cannot reference the value of "a" (and vice-versa).

5.2.1 Attribute Details

Name Required Attribute Constraints Type Default Value Valid Values Description
ID true ID none The name of the data item. It MUST be unique within the document.
src false URI none Any URI referencing a legal data value. See 8.3 Legal Data Values and Value Expressions for details. Gives the location from which the data object should be downloaded.
expr false Expression none Any valid value expression Evaluates to provide the value of the data item. See 8.3 Legal Data Values and Value Expressions for details.

5.2.2 Children

The children of the <data> element represent an in-line specification of the value of the data object.

At most one of "src" and "expr" may occur. If either is present, then the element MUST not have any children. Thus "src", "expr" and children are mutually exclusive inside the <data> element.

In addition to the "src" attribute and in-line child elements, values for the top-level <data> elements can be provided by the environment at instantiation time. The exact mechanism for this is implementation dependent, but values provided at instantiation time override those contained in the <scxml> element, whether they are specified in-line or via the "src" attribute.

If the value specified (by 'src', children, or the environment) is not a legal data value, the error error.invaliddata is raised at load time, and an empty data element is created in the data model with the specified ID. Note that what constitutes a legal data value depends on the data model language used. See 9 Profiles for details.

The <assign> element may be used to modify the data model.

5.3 <assign>

5.3.1 Attribute Details

Name Required Attribute Constraints Type Default Value Valid Values Description
location true path expression none Any valid location expression. The location in the data model into which to insert the new value. See 8.2 Location Expressions for details. Note that in the case of an XML data model (see ), it is not required to assign to the root of a tree (i.e., the "name" value in a <data> tag), since the path expression can reach down into the tree to assign a new value to an internal node.
dataID false idref none The ID of any <data> element in the document The 'id' of a <data> element. If it is provided, the 'location' expression is interpreted as applying to the children of this <data> element. If the 'dataID' is not specified, the 'location' expression is interpreted as applying to the children of the <datamodel> element. This attribute allows a more succinct notation when XPath is used as the expression language, as indicated in and in the examples below.
expr false value expression none Any valid value expression An expression returning the value to be assigned. See 8.3 Legal Data Values and Value Expressions for details. If 'expr' is specified, no children are permitted.

5.3.2 Children

The children of the <assign>element provide an in-line specification of legal data value (see 8.3 Legal Data Values and Value Expressions) to be inserted into the datamodel at the specified location.

If "expr" is present, then the element MUST not have any children. Thus "expr" and children are mutually exclusive inside the <assign> element.

Assignment to a data model is done by using a location expression to denote the part of the data model where the change is to be made. If the location expression does not denote a valid location in the datamodel an error error.illegalalloc is raised. If the value specified (by 'expr' or children) is not a legal value for the location specified, the error error.invaliddata is raised. Note that what constitutes a legal value depends on the data model language used. See 9 Profiles for details.

5.4 <validate>

The <validate> element causes the datamodel to be validated. Note that validation of the datamodel occurs only when explicitly invoked by this element.

5.4.1 Attribute Details

Name Required Attribute Constraints Type Default Value Valid Values Description
location false location expression none Any valid location expression. The location of the subtree to validate. If it is not present, the entire datamodel is validated. See 8.2 Location Expressions for details.
schema false URI none Any valid URI The location of the schema to use for validation. If this attribute is not present, the schema specified in the top-level <datamodel> is used. An error error.validate.validationfailure will be raised at document load time if no schema is specified in either element.

5.4.2 Children

None.

5.5 System Variables

The Data Module maintains a protected portion of the data model containing information that may be useful to applications. We refer to the items in this special part of the data model as 'system variables'. Implementations that include the Data Module MUST provide the following system variables, and MAY support others.

  • _event. The variable 'event' is bound to a structure containing the current event's name and any data contained in the event. The exact nature of the structure depends on the datamodel being used. See 9 Profiles for details. In the executable content of <onentry>, <onexit> and <transition> elements, the current event is defined to be the event that triggered the transition, if there is one. In the "cond" attribute of <transition>, the current event is the one that is currently being matched against the transition, if there is one. In all other locations, 'event' is undefined. Note, in particular, that 'event' is not bound when the system is evaluating or taking a transition that lacks an "event" attribute.

    If the data in the event is not a legal instance of the data model language, and the system cannot translate it into one, then at the point at which the system attempts to bind 'event', the error error.invaliddata will be raised and the event data part of the 'event' structure will not be bound. The event's name will still be available, however. Processing of both the original event and the error event will proceed as usual.

  • _sessionID. The variable 'sessionID' is bound at load time to the system-generated ID for the current SCXML session. It remains bound until the session terminates.

  • _name. The variable 'name' is bound at load time to the name of the state machine, which is specified in the "name" attribute of the <scxml> element. It remains bound until the session terminates.

The set of system variables may be expanded in a future version of this specification. Therefore developers SHOULD NOT use IDs beginning with '_' in the <data> element since this may cause forwards-compatibility problems.

The concrete realization of these variables in a specific data model depends on the language used. For the exact location of these variables in an XML data model, see 9.3 The XPath Profile. All system variables are protected and any attempt to change their values MUST fail and result in the error error.illegalassign being raised.

6 Script Module

6.1 <script>

The Script Module adds scripting capability to the state machine. Its schema may be found at D.5 Schema for Script Module. Profiles including the Script Module MUST:

  • Redefine the executable content group to include the <script> tag.

For an example of how to do this, see 9.2 The ECMAScript Profile.

6.1.1 Attribute Details

None.

6.1.2 Children

The children of the <script> element represent the script code to be executed.

7 Anchor Module

The <anchor> module is intended to provide 'go back' or 'redo' functionality that is useful in some applications. An anchor MAY be specified instead of a "target" for the transition. In this case, the system transitions to the last state visited containing an <anchor> whose "type" matches the "anchor" specified in the transition.

When a state containing an <anchor> element is entered, a snapshot of the data model is taken before the state's <onentry> handler is executed. The default is to snapshot the entire datamodel, but the application author can restrict the snapshot to part of the datamodel using the 'snapshot' attribute. When a transition is taken with an 'anchor' as its target, the state machine returns to the most recently-visited state with an <anchor> whose 'type' attribute matches the 'anchor' in the transition. In the course of the transition, before the state containing the anchor element is entered, the datamodel is restored from the snapshot. The effect is thus to jump back and restart processing at that state. As part of this restart, all intermediate anchors are erased. Intermediate anchors are those that were set between the time the anchor state was last visited and the point at which the transition with the anchor state as target is taken. Note that all these anchors must have a different type from the one that is the target of the transition. If no state with a matching <anchor> type has been visited, the current state is exited and re- entered. For a complete definition of the semantics of <anchor>, see B Algorithm for SCXML Interpretation. For the schema of the Anchor Module, see D.6 Anchor Module Schema .

The ability to reset the datamodel may lead to accidental, unterminated loops in the state machine. The interpreter context MAY detect these and exit.

Profiles that includ the Anchor Module MUST:

7.1 <anchor>

7.1.1 Attribute Details

Name Required Attribute Constraints Type Default Value Valid Values Description
type true xsd:NMTOKEN none Defines the type of this anchor instance.
snapshot false path expression none Any expression denoting a node in the data model. A location in the datamodel to snapshot. If no snapshot value is provided, the entire data model is copied. Implementations MUST support XPath [XPath] as a path expression language and MAY support other languages if they choose.

7.1.2 Children

None.

8 Expressions

SCXML contains three types of expressions, as described below. Different profiles of SCXML will support different languages for these expression types, but certain properties of the expressions are constant across profiles and are defined here.

Expressions MUST not contain side effects that would effect the datamodel or the execution of the state machine. Implementations MAY assume that expressions do not have side effects when optimizing expression evaluation. Thus expressions may not be evaluated as often as indicated in B Algorithm for SCXML Interpretation or at the same points in the algorithm.

8.1 Conditional Expressions

Conditional expressions are used inside the 'cond' attribute of <transition>, <if> and <elseif>. If a conditional expression does not evaluate to a boolean value ('true' or 'false'), the error 'error.illegalcond' is raised. The set of operators in conditional expressions varies depending on the profile, but all profiles must support the 'In()' predicate, which is used to test whether the state machine is in a given state. This predicate allows coordination among parallel regions.

8.2 Location Expressions

Location expressions are used to specify a location in the datamodel as part of the <assign>element. The exact nature of a location depends on the profile. For example, in the XPath Profile (9.3 The XPath Profile), the underlying datamodel is an XML tree and a location expression must evaluate to an existing node or nodeset in the datamodel. If a location expression does not evaluate to a legal location, an error error.illegalalloc is raised.

8.3 Legal Data Values and Value Expressions

Any profile that includes the Data Module must specify the structure of the underlying data model. For example, the XPath Profile (9.3 The XPath Profile) defines the data model to be an XML tree. Such a specification of the data model implicitly defines a set of "legal data values", namely the objects that can be part of such a data model. For an XML data model, the set of legal data values consists of XML trees and subtrees, plus strings (as values of attributes or text children). In conjunction with this, the Profile must define a set of value expressions which can be evaluated at runtime to return legal data values. If a value expression does not return a legal data value, the error error.illegalvalue is raised.

8.4 Errors in Expressions

Implementations MAY raise errors caused by syntactically ill-formed expressions at document load time, or they MAY wait and raise these errors at runtime when the expressions are evaluated. Implementations MUST raise errors caused by expressions returning illegal values at the points at which B Algorithm for SCXML Interpretation indicates that the expressions are to be evaluated. Note that this requirement holds even if the implementation is optimizing expression evaluation.

9 Profiles

To define a profile, you must first specify the list of modules that the profile includes. This list MUST include the Core module and MAY include other ones. In addition to this list you must:

9.1 The Minimal Profile

9.1.1 Conformance

The Minimal profile defines a stripped down state machine with no external communications or data model, but with full Harel semantics. Conformant SCXML processors must implement the following modules:

For the schema of theMinimal profile, see D.7 Minimal Profile Schema.

9.1.2 Core Module Requirements

No elements or attributes are extended or redefined. For the schema of the Minimal Profile, see D.7 Minimal Profile Schema.

9.1.2.1 Conditional Expressions

The boolean expression language consists of the In predicate only. It has the form 'In(id)', where id is the id of a state in the enclosing state machine.

9.2 The ECMAScript Profile

9.2.1 Conformance

This section contains information which is specific to the SCXML ECMAScript profile. In particular, it defines the semantics of using ECMAScript in binding expressions for data model access, conditional evaluation, and value expressions in SCXML. It also defines use of the <script> element in this profile.

Conformant SCXML processors must implement the following modules from SCXML:

  • core module
  • data module
  • script module

Conformant documents must specify a value of profile="ecmascript" on the root <scxml> element.

In addition, conformant implementations of the ECMAScript Profile for SCXML 1.0 must support ECMAScript Compact Profile [ECMASCRIPT-327], a strict subset of the third edition of ECMAScript [ECMASCRIPT-262]. A conformant implementation may support ECMAScript for XML (E4X) [E4X].

Editorial note  

A later version of this specification will clarify how XML data can accessed, manipulated and generated using this profile. Apart from E4X, we are also considering DOM access functions and ECMAScript 4.0 (4th edition of ECMAScript 262).

ECMAScript 4.0 is still under development. The specifications are not yet public. An overview has been published. Many elements of the new language will be familiar to Action Script developers. There are early implementation from Mozilla and on ecmascript.org.

9.2.2 Core Module Requirements

9.2.2.1 Conditional Expressions

ECMAScript expressions used in conditional expressions are converted into their effective boolean value using the ToBoolean operator as described in Section 9.2 of [ECMASCRIPT-262]. The expression is evaluated in its own local scope, and allows (read only) access to variables and functions in the global scope, including the data model (see 9.2.3 Data Module Requirements for scoping model).

The following example illustrates this usage.

Example: Use of a boolean expression to determine whether or not a transition is taken.
<state id="errorSwitch">
  <datamodel>
   <data ID="time"/>
  </datamodel>
        
  <onentry>
    <assign location="_data.time" expr="currentDateTime()"/>
  </onentry>
          
  <transition cond="yearFromDatetime(_data.time) > 2009" target="newBehavior"/>
 
  <transition target="currentBehavior"/>
</state>

Any errors which arise during the processing of a conditional expression must be mapped into an SCXML error.illegalcond.errortype event where the optional errortype indicates the ECMAScript error type as specified in Section 15.11.6 of [ECMASCRIPT-262]. For instance, an ECMAScript expression which attempts to assign a value to a variable defined in the global scope would generate an error.illegalcond event.

Conditional expressions may take advantage of the In() predicate. Additional detail appears in 9.2.5.1 The In() predicate.

9.2.3 Data Module Requirements

The underlying data model is the subset of the ECMAScript object model as defined by JSON [RFC4627]. SCXML data model expressions are evaluated as ECMAScript expressions in global or local scope as described later in this section.

The SCXML datamodel is implemented as an ECMAScript object with the name _data.

In a <datamodel> element, each <data> child is bound to a property of the _data object. The property name is the value of the ID attribute of <data>. The value of the property is assigned by the evaluation one of the following expressions:

  • value of the expr attribute
  • resource referenced by the value of the src attribute. JSON resources have the mime type application/json.
  • inline content
If no value is assigned, the property has the default value ECMAScript undefined.

Evaluation of JSON expressions must be supported and evaluation of XML expressions may be supported.

The _data object must be created by the processor upon initialization of the SCXML document. Any errors which arise during initialization must be mapped into an SCXML error.illegaldata.errortype event where the optional errortype indicates an ECMAScript error type as specified in Section 15.11.6 of [ECMASCRIPT-262]. For example, an error will be raised if the <data> element's ID attribute is not a valid ECMAScript variable name or if the evaluation of the expr attribute value fails.

Example: Datamodel <data> initialization
<scxml version="1.0" profile="ecmascript">
  <datamodel>
   <data ID="employees" src="http://example.com/employees.json"/>
   <data ID="year" expr="2008"/>
   <data ID="CEO" expr="\"Mr Big\""/>
   <data ID="profitable" expr="true"/>
  </datamodel>
</scxml>

This profile uses ECMAScript scoping. Elements in the SCXML document are associated with ECMAScript scopes which themselves are chained together. Scopes are created when the SCXML processor enters specific elements, and the scope is destroyed when processor exits the element. This profiles defines two ECMAScript scopes: global and local.

A global scope must be defined for each SCXML session. The global scope is created when the SCXML session is created. The SCXML datamodel is contained within the global scope. The global scope has no parent scope.

The SCXML elements <state>, <parallel>, <final> and <transition>, as well as cond attributes, are each associated with an ECMAScript local scope. The local scope always has the global scope as its parent. Consequently, variables and function prototypes in the global scope are accessible through this scope chain.

Variable bindings take place in the local scope except for bindings to the variables defined in the global scope. Consequently, bindings to the datamodel (_data object) are applied at global scope.

References to variables in the global and local scopes can be disambiguated by explicit scope designation: prepending the scope name plus "." to the variable name. For example, global.time identifies a variable with the name time in global scope, while local.time identifies a variable the same name in local scope. A variable reference without an explicit scope designation, references a variable in the local scope if defined, otherwise references a variable in the global scope.

Variables bindings are defined for the lifecycle of the respective scope.

Editorial note  

We solicit feedback on whether only two scopes, local and global, are sufficient for applications.

9.2.3.1 Location Expressions

ECMAScript left-hand-side expressions are used to select an object (or sub-property of an object) from the data model by providing a binding expression. The following example illustrates this usage:

Example: Use of the location attribute of the assign to update the salary of an employee.
<state id="errorSwitch">
    <datamodel>
      <data ID="employees" src="http://example.com/employees.json"/>
    </datamodel>
    
    <onentry>
        <assign location="_data.employees.employee[12].salary" expr="42000"/>
    </onentry>
</state>

Any errors which arise during the processing of a location expression must be mapped into an SCXML error.illegalalloc.errortype event where the optional errortype indicates the ECMAScript error type as specified in Section 15.11.6 of [ECMASCRIPT-262]. For example, an error will arise if there is an attempt to assign a value to a system variable (9.2.3.3 System Variables).

9.2.3.2 Value Expressions

The result of any ECMAScript expression may be used in a value expression.

Example: Copying event data into the local data model for the state.
<state id="processEvent">
    <datamodel>
        <data ID="myEvent"/>
    </datamodel>
    
    <onentry>
        <assign location="_data.myEvent" expr="_data._event"/>
    </onentry>
</state>

Any errors which arise during the processing of a value expression must be mapped into an SCXML error.illegalvalue.errortype event where the optional errortype indicates the ECMAScript error type as specified in Section 15.11.6 of [ECMASCRIPT-262].

9.2.3.3 System Variables

System variables are defined as ECMAScript read-only variables in global scope. The _event system variable is defined as an object with two properties: name (String value) for the name of the event; and data (Object value) exposing the event data payload. The _sessionID and _name system variables are defined as variables with ECMAScript String values.

The _event value must be assigned by processor before triggering executable content in the <onentry>, <onexit>, and <transition> elements which may reference the variable. The processor must clear the value by setting _event to ECMAScript undefined values when event processing has completed.

The _sessionID and _name values must be set by the processor at session start.

Example: Accessing system _event name in a condition
<state id="checkSessionID">
    <transition cond="_event.name=='connector.sip.invite'" target="nextState">
     ...
    </transition>
</state>

9.2.4 Script Module Requirements

Editorial note  

This section is tentative and subject to revision in a later version of this specification.

In this profile, the inline content of the <script> is an ECMAScript program as defined in Section 14 of [ECMASCRIPT-262].

This profile allows <script> elements to occur as children of <scxml> elements and within executable content.

When a <script> element is a child of <scxml> its contents are evaluated in global scope at document load time. Defined variables and functions are available through the scope chain to expressions in local scope.

When a <script> element occurs within executable content it is evaluated in the local scope associated with the containing element (or its ancestor).

Any errors which arise during processing of <script> content must be mapped into an SCXML error.script.errortype event where the optional errortype indicates the ECMAScript error type as specified in Section 15.11.6 of [ECMASCRIPT-262].

Example: <script> in <scxml> to define global variable and function
<scxml version="1.0" profile="ecmascript">
  <script>
       var globalCounter = 0;

       function updateCounter() {
        globalCounter++;
       }
  </script>
</scxml>
Example: <script> in executable content to manipulate the data model
<state id="updateDM">
    <onentry>
      <script>
        _data.myDate = new Date(); 
        updateCounter();
      </script>
    </onentry>
</state>
Editorial note  

A later version will clarify how inline ECMAScript interacts with fetched ECMAScript programs (where external fetching takes place at document initialization, evaluation when the element is executed).

9.2.5 Additional Requirements

9.2.5.1 The In() predicate

A conformant SCXML processor must add an ECMAScript function to the SCXML namespace that implements the In() semantics described in section 8.1 of the [SCXML1] specification.

Function signature: In($arg as xs:string?) as xs:boolean

Returns an xs:boolean indicating whether or not one of the current active states matches the value of $arg.

9.2.6 Examples

Editorial note  

Detailed examples will be provided in a later version of this specification.

9.3 The XPath Profile

9.3.1 Conformance

This specification contains information which is specific to the SCXML XPath profile. In particular, it defines the semantics of using XPath in binding expressions for data model access, conditional evaluation, and value expressions in SCXML.

Conformant SCXML processors must implement the following modules from SCXML

Conformant documents must specify a value of profile="xpath" on the root <scxml> element.

In addition, conformant implementations of the XPath Profile for SCXML 1.0 must support [XPath 2.0].

For the schema of the XPath profile, see D.9 XPath Profile Schema.

9.3.2 Core Module Requirements

9.3.2.1 Conditional Expressions

XPath 2.0 expressions used in conditional expressions are converted into their effective boolean value as described in section 2.4.3 of the [XPath 2.0] specification. The following example illustrates this usage.

Example: Use of a boolean expression to determine whether or not a transition is taken.
<state id="errorSwitch" xmlns:fn="http://www.w3.org/2005/xpath-functions">
  <datamodel>
    <data ID="time"/>
  </datamodel>
          
  <onentry>
    <assign location="instance('time')" expr="fn:current-dateTime()"/>
  </onentry>
          
  <transition cond="fn:year-from-dateTime(/data[@ID='time']) > 2009" target="newBehavior"/>
  <transition target="currentBehavior"/>
</state>
        

Any errors which arise during the processing of a conditional expression must be mapped into an SCXML error.illegalcond.errorcode event where the errorcode is the value specified in [XPath 2.0] and related specifications such as the [XPath 2.0 Functions and Operators]. For instance, an XPath expression which attempts to use a component having an undefined value would generate an error.illegalcond.XPST0001 event.

Conditional expressions may take advantage of the In() predicate. Additional detail appears in 9.3.4.1 The In()