# \<grammar>

## \<grammar> <a href="#grammar" id="grammar"></a>

The `<grammar>` element is used to provide a speech (or DTMF) grammar that:

* Specifies a set of utterances or DTMF key presses that a user may speak or type to perform an action or supply information.
* Returns a corresponding semantic interpretation for a matching input.

### Attributes

<table><thead><tr><th width="186.33333333333331">Name</th><th width="146">Data type<select><option value="bf3b46db79974354850bf945aa48c8f4" label="String" color="blue"></option><option value="4d34b20185be448e99feda97b6f94005" label="Integer" color="blue"></option><option value="7ad3d523933047fb9317a9f270974088" label="Boolean" color="blue"></option></select></th><th>Description</th></tr></thead><tbody><tr><td>fetchhint</td><td></td><td>This attribute is not supported.</td></tr><tr><td>fetchtimeout</td><td><span data-option="bf3b46db79974354850bf945aa48c8f4">String</span></td><td>(defaults to “fetchtimeout” global property value) The timeout for fetches. Must be specified with the appropriate time units (e.g., “120s” for 120 seconds).</td></tr><tr><td>maxage</td><td><span data-option="bf3b46db79974354850bf945aa48c8f4">String</span></td><td>(defaults to “grammarmaxage” global property value) Tells the platform the maximum acceptable age, in seconds, of cached grammars.</td></tr><tr><td>maxstale</td><td><span data-option="bf3b46db79974354850bf945aa48c8f4">String</span></td><td>(defaults to “grammarmaxstale” global property value) Tells the platform the maximum acceptable staleness, in seconds, of expired cached grammars.</td></tr><tr><td>scope</td><td><span data-option="bf3b46db79974354850bf945aa48c8f4">String</span></td><td><p>Accepted values include "document" or "dialog".</p><p></p><p>“document” makes the grammar active in all dialogs of the current document (and relevant application leaf documents).</p><p></p><p>“dialog” makes the grammar active throughout the current form.<br><br>If this attribute is omitted, the grammar scoping is resolved by looking at the parent element.</p></td></tr><tr><td>src</td><td><span data-option="bf3b46db79974354850bf945aa48c8f4">String</span></td><td><p>The URI specifying the location of the grammar. </p><p></p><p>Specifying the rule name within the URI is not supported. If you wish to load a particular rule from a grammar, declare that rule “public”.</p><p></p><p>See Section 3.2 for details.</p></td></tr><tr><td>srcexpr</td><td><span data-option="bf3b46db79974354850bf945aa48c8f4">String</span></td><td>Dynamically determine the URI to fetch by evaluating this ECMAScript expression.</td></tr><tr><td>type</td><td><span data-option="bf3b46db79974354850bf945aa48c8f4">String</span></td><td><p>The media type of the grammar. Supported values are “application/x-jsgf” and “application/srgs+xml”.</p><p></p><p>This attribute takes precedence over other possible sources of the media type (for instance, the “Content-type” field in an HTTP or RTSP exchange, or the file extension).</p></td></tr><tr><td>xml:base</td><td><span data-option="bf3b46db79974354850bf945aa48c8f4">String</span></td><td>Declares the base URI from which relative URIs are resolved.</td></tr><tr><td>tag-format</td><td></td><td>This attribute is not supported.</td></tr><tr><td>version</td><td></td><td>This attribute is not supported.</td></tr><tr><td>xml:lang</td><td><span data-option="bf3b46db79974354850bf945aa48c8f4">String</span></td><td>The language declaration provides the language identifier that indicates the primary language contained by the grammar and optionally indicates a country or other variation.</td></tr><tr><td>root</td><td><span data-option="bf3b46db79974354850bf945aa48c8f4">String</span></td><td><p>Declares a single rule to be the root rule of the grammar. Becomes required when specifying inline SRGS+XML grammars.</p><p></p><p>The declared rule 1) must be defined within the scope of the grammar and 2) may be scoped as either public or private.</p></td></tr><tr><td>mode</td><td><span data-option="bf3b46db79974354850bf945aa48c8f4">String</span></td><td>Defines the type of grammar to be loaded. Accepted values are “dtmf” or “voice”.</td></tr><tr><td>weight</td><td><span data-option="4d34b20185be448e99feda97b6f94005">Integer</span></td><td>Specifies the weight of the grammar.</td></tr><tr><td>maxdigits</td><td><span data-option="bf3b46db79974354850bf945aa48c8f4">String</span></td><td><p>Specifies the maximum digits allowed for your grammar.</p><p></p><p>Can be used with the property type, termmaxdigits.</p></td></tr></tbody></table>

### Notes

Plum DEV includes support for JSGF and SRGS+XML. The default grammar format is JSGF. Grammar types are specified using the “type” attibute. For JSGF, use “application/x-jsgf” and for SRGS+XML, use “application/srgs+xml”.

### Example

```markup
<?xml version="1.0"?>
<vxml version="2.0">
  <form>
    <field name="myfield">
      <!-- Multiple grammars can be specified either by including -->
      <!-- several grammar blocks within the field item or by -->
      <!-- specifying a built-in grammar with the "field" tag's -->
      <!-- "type" attribute. -->
      <grammar type="application/x-jsgf" mode="dtmf">
        ( 1 | 2 )+
      </grammar>
      <grammar type="application/x-jsgf" mode="voice">
        ( one | two )+
      </grammar>
      <prompt>
        Say or enter any number of the digits one or two.
      </prompt>
      <filled>
        You entered <value expr="myfield"/>.
      </filled>
      <nomatch>
        You did not say or enter any ones or twos.
        <reprompt/>
      </nomatch>
      <noinput>
        You did not enter anything.
        <reprompt/>
      </noinput>
    </field>
  </form>
</vxml>
```

The output of the above script would be:

> Computer: Say or enter any number of the digits one or two.\
> Human: (enters DTMF-5)\
> Computer: You did not say or enter any ones or twos.\
> Computer: Say or enter any number of the digits one or two.\
> Human: (silently waits for prompt to timeout)\
> Computer: You did not enter anything.\
> Computer: Say or enter any number of the digits one or two.\
> Human: One two one two.\
> Computer: You entered one two one two.

### Child Tags

[\<lexicon>](https://docs.plumvoice.com/dev/voicexml/tags/lexicon-tag), [\<meta>](https://docs.plumvoice.com/dev/voicexml/tags/meta-tag), [\<metadata>](https://docs.plumvoice.com/dev/voicexml/tags/metadata-tag), [\<rule>](https://docs.plumvoice.com/dev/voicexml/tags/rule-tag)

### Parent Tags

[\<choice>](https://docs.plumvoice.com/dev/voicexml/tags/choice-tag), [\<field>](https://docs.plumvoice.com/dev/voicexml/tags/field-tag), [\<form>](https://docs.plumvoice.com/dev/voicexml/tags/form-tag), [\<link>](https://docs.plumvoice.com/dev/voicexml/tags/link-tag), [\<record>](https://docs.plumvoice.com/dev/voicexml/tags/record-tag), [\<transfer>](https://docs.plumvoice.com/dev/voicexml/tags/transfer-tag)
