SrgsRuleRef Constructor (Uri)

Initializes a new instance of the SrgsRuleRef class, specifying the Uniform Resource Identifier (URI) of the grammar to reference.

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


Public Sub New ( _
    uri As Uri _
public SrgsRuleRef (
    Uri uri
SrgsRuleRef (
    Uri^ uri
public SrgsRuleRef (
    Uri uri
public function SrgsRuleRef (
    uri : Uri


  • uri
    The URI of the rule to reference.


Exception type Condition

uri is null.


The syntax for uri will vary, depending on whether it references a rule in the same grammar or in an external grammar. For more information, see Uri.


The following example creates a grammar for an application that returns information about bus shuttle service. The first method, GrammarUrlForRoute, takes a string that specifies a route and appends it to a string specifying the location of a grammar. This specifies a particular rule in that grammar. The method returns a Uri for that rule.

The second method, CreateGrammarForRoute, creates an SrgsDocument element named grammar with a rule reference specified by the Uri passed to it by GrammarUrlForRoute. Note that the variable named _route is a member of an enclosing class.

private Uri GrammarUrlForRoute(string route)
  return new Uri("http://localhost/MyBus/MyBusLocations.grxml#LocationsForRoute" + route);

private SrgsDocument CreateGrammarForRoute()
  SrgsDocument grammar = new SrgsDocument();
  grammar.Mode = SrgsGrammarMode.Voice;
  SrgsRule rule = new SrgsRule("LocationsForRoute" + _route);
  SrgsRuleRef ruleref = new SrgsRuleRef(GrammarUrlForRoute(_route));

  SrgsTag tag = new SrgsTag("$.Location = $$");

  grammar.Root = rule;
  return grammar;


The variable named _route is undeclared and undefined in the preceding sample. It should be declared as a string and contain the route number for a particular bus route before the preceding sample is compiled and run.


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


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