XML templates are specified for a grammar element by placing one of the following tags within it:

Tag

Purpose

<xml-template>

Encloses an XML fragment that is associated with the grammar element. If the grammar element has children with their own XML templates, then an embedded <apply-xml-templates/> element determines the location in the fragment at which the children’s associated XML will be spliced in.

<xml-empty-template/>

Specifies that the grammar element is associated with the absence of any parsed or emitted XML. This is only meaningful when other alternative constructs in a choice have non-empty XML templates.

<xml-template-attribute name="..."/>

Specifies that the grammar element is associated with an XML attribute.

Here is an example to clarify the use of XML templates. Suppose you have a custom scenario action whose expression grammar takes the following form:

Perform action in ( this way | that way ) on [literal]

This action will be represented as a sequence beginning with the token Perform MyAction in, followed by a choice of tokens this way and that way, followed by the on token, and finally a literal for the user to supply a value. In the case where the token this way is chosen, the expression will correspond to the following PDL fragment (all of which would be automatically enclosed in an <action> element by the scenario editor):

<action-name>MyAction</action-name>
<action-param name="mode">
  <constant>this</constant>
</action-param>
<action-param name="value">
  <constant type="java.lang.Integer">value</constant>
</action-param>

(In the case where that way is chosen, the PDL would be identical but the value of the mode argument would be that.)

The expression grammar for such a custom action could look like this:

<sequence id="action-MyAction">
  <!-- XML template specifying the action name.  Child elements' XML will
       be processed following the <action-name> element. -->
  <xml-template>
    <action-name>myAction</action-name>
    <apply-xml-templates/>
  </xml-template>
  <!-- "noise" token that simply acts as a choice handle in the UI;
       it is not associated with any PDL. -->
  <token><description>Perform action</description></token>
  <!-- further "noise" token providing connective to choice.  We
       separate it because "Perform action" is nicer in a dropdown
       list than "Perform action in". -->
  <token><description>in</description></token>
  <!-- choice of mode arguments -->
  <choice>
    <!-- XML template specifying the "mode" parameter.  This XML
         template is processed where the <apply-xml-templates/>
         element occurred in the parent sequence's template, so the
         parameter will follow the <action-name> element. -->
    <xml-template>
      <action-param name="mode">
        <constant><apply-xml-templates/></constant>
      </action-param>
    </xml-template>
    <!-- mode tokens.  Because these have values, the tokens are
         associated with XML text nodes at the point where the
         <apply-xml-templates/> element occurred in the parent
         choice's template, i.e. within the <constant> element. -->
    <token value="this"><description>this way</description></token>
    <token value="that"><description>that way</description></token>
  </choice>
  <token><description>on</description></token>
  <literal>
    <!-- XML template for the "value" parameter.  Note that the
         value of the literal will be associated with an XML text
         node processed at the point of <apply-xml-templates/>. -->
    <xml-template>
      <action-param name="value">
        <constant><apply-xml-templates/></constant>
      </action-param>
    </xml-template>
    <required/>
    <default><value type="java.lang.Integer">1</value></default>
  </literal>
</sequence>

Copyright © 1997, 2012 Oracle and/or its affiliates. All rights reserved. Legal Notices