SrgsRule Constructor (String)

Initializes a new instance of the SrgsRule class with the given identifier.

Namespace: Microsoft.Speech.Recognition.SrgsGrammar
Assembly: Microsoft.Speech (in microsoft.speech.dll)




  • id
    A string that is the identifier of the rule. The identifier must be unique within a given grammar.


Exception type Condition

id is null.


id is empty.


id is not a proper rule identifier.


The SrgsRule(string) constructor initializes the Id property.

The SrgsRule(string) constructor throws FormatException in the following circumstances:

  • id is not a valid XML name, as defined in Extensible Markup Language (XML) 1.0 (Second Edition)—see To paraphrase this definition, a valid XML name must begin with a letter, an underscore ('_'), or a colon (':') and can be followed by zero or more NameChar characters (also defined in the XML specification).

  • id is "NULL" or "VOID" or "GARBAGE".

  • id contains at least one invalid rule ID character. These characters are: '?', '*', '+', '|', '(', '), '^', '$', '/', ';', '.', '=', '<', '>', '[', ']', '{', '}', '\\', ' ', '\t', '\r', and '\n'.


The following example creates an inline grammar with a single SrgsRule element named rule1 containing a rule whose identifier is rootRule and adds an SrgsOneOf element to the Elements property of the SrgsRule element. The SrgsOneOf element consists of SrgsItem elements containing alternatives to be recognized by the rule.

/// <summary>
/// Create an inline grammar
/// </summary>
/// <param name="mode">recognition mode: dtmf or voice</param>
protected void CreateInlineGrammar(SrgsGrammarMode mode)
  SrgsDocument grammar1 = new SrgsDocument();
  grammar1.Culture = Thread.CurrentThread.CurrentUICulture;
  grammar1.Mode = mode;

  //rule name is language independent 
  SrgsRule rule1 = new SrgsRule("rootRule");
  grammar1.Root = rule1;

  ResourceInfo resources = TaskletHost.Resources;

  SrgsOneOf ListOfAlternatives = new SrgsOneOf();

  if (resources.GrammarTexts != null)
    foreach (string alternative in resources.GrammarTexts)
      ListOfAlternatives.Add(new SrgsItem(alternative));
  inlineGrammar = new Grammar(grammar1);


Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Vista Ultimate Edition, Windows Vista Business Edition, Windows Vista Enterprise Edition

Target Platforms

See Also


SrgsRule Class
SrgsRule Members
Microsoft.Speech.Recognition.SrgsGrammar Namespace