Share via


SrgsDocument.WriteSrgs Method

Writes an SRGS XML document.

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

Syntax

'Declaration
Public Sub WriteSrgs ( _
    srgsGrammar As XmlWriter _
)
public void WriteSrgs (
    XmlWriter srgsGrammar
)
public:
void WriteSrgs (
    XmlWriter^ srgsGrammar
)
public void WriteSrgs (
    XmlWriter srgsGrammar
)
public function WriteSrgs (
    srgsGrammar : XmlWriter
)

Parameters

  • srgsGrammar
    The System.Xml.XmlWriter that is used to write the SrgsDocument instance.

Exceptions

Exception type Condition
ArgumentNullException

srgsGrammar is null.

Example

The following example creates an SrgsDocument object, and then creates a public rule named rootRule. It then creates an SrgsItem that consists of the string "A nation that has won the world cup is:", and adds this item to the Elements property of the rule. The example then creates two more rules (ruleEurope and ruleSAmerica), each of which is an SrgsOneOf object that contains three SrgsItem objects. After that, another SrgsOneOf object is created that contains SrgsRuleRef objects that refer to ruleEurope and ruleSAmerica. The new SrgsOneOf object is then added to the Elements property of rootRule. After this, all three rules (rootRule, ruleEurope, and ruleSAmerica) are added to the Rules property of SrgsDocument. Finally, the three rules are compiled into a binary representation of the grammar.

SrgsDocument document = new SrgsDocument();
SrgsRule rootRule = new SrgsRule("WorldCupWinner");
rootRule.Scope = SrgsRuleScope.Public;

rootRule.Elements.Add(new SrgsItem("A nation that has won the world cup is: "));
SrgsOneOf oneOfEurope = new SrgsOneOf(new SrgsItem("England"), new SrgsItem("France"), new SrgsItem("Germany"), new SrgsItem("Italy"));
SrgsRule ruleEurope = new SrgsRule("EuropeanNations", oneOfEurope);

SrgsOneOf oneOfSAmerica = new SrgsOneOf(new SrgsItem("Argentina"), new SrgsItem("Brazil"), new SrgsItem("Uruguay"));
SrgsRule ruleSAmerica = new SrgsRule("SouthAmericanNations", oneOfSAmerica);

rootRule.Elements.Add(new SrgsOneOf(new SrgsItem(new SrgsRuleRef(ruleEurope)), new SrgsItem(new SrgsRuleRef(ruleSAmerica))));

document.Rules.Add(rootRule, ruleEurope, ruleSAmerica);
document.Root = rootRule;

string srgsDocumentFile = Path.Combine(Path.GetTempPath(), "srgsDocumentFile.xml");

XmlWriter writer = XmlWriter.Create(srgsDocumentFile);

document.WriteSrgs(writer);
writer.Close();

Thread Safety

All public static (Shared in Visual Basic) members of this type are thread-safe. Instance members are not guaranteed to be thread-safe.

Platforms

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

Reference

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