SrgsDocument.WriteSrgs(XmlWriter) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Escreve o conteúdo do SrgsDocument objeto num ficheiro gramatical em formato XML que cumpre a Especificação de Gramática de Reconhecimento de Fala (SRGS) Versão 1.0.
public:
void WriteSrgs(System::Xml::XmlWriter ^ srgsGrammar);
public void WriteSrgs(System.Xml.XmlWriter srgsGrammar);
member this.WriteSrgs : System.Xml.XmlWriter -> unit
Public Sub WriteSrgs (srgsGrammar As XmlWriter)
Parâmetros
- srgsGrammar
- XmlWriter
O XmlWriter que é usado para escrever a SrgsDocument instância.
Exceções
srgsGrammar é null.
Exemplos
O exemplo seguinte cria um SrgsDocument objeto, e depois cria uma regra pública chamada winnerRule. Depois cria um SrgsItem que consiste na sequência "Uma nação que venceu a Taça do Mundo é:", e adiciona este item à Elements propriedade da regra. O exemplo cria então mais duas regras (ruleEurope e ruleSAmerica), cada uma das quais é um SrgsOneOf objeto que contém três SrgsItem objetos. Depois disso, é criado outro SrgsOneOf objeto que contém SrgsRuleRef objetos que se referem a ruleEurope e ruleSAmerica. O novo SrgsOneOf objeto é então adicionado à Elements propriedade de winnerRule. Depois disso, as três regras (winnerRule, , e ruleEurope) são adicionadas à ruleSAmerica propriedade do RulesSrgsDocument. Finalmente, o exemplo cria um ficheiro XML vazio e uma instância de XmlWriter. O WriteSrgs método utiliza a XmlWriter instância para escrever o conteúdo do SrgsDocument no ficheiro XML.
public void WorldSoccerWinners ()
{
// Create an SrgsDocument, create a new rule
// and set its scope to public.
SrgsDocument document = new SrgsDocument();
SrgsRule winnerRule = new SrgsRule("WorldCupWinner");
winnerRule.Scope = SrgsRuleScope.Public;
// Add the introduction.
winnerRule.Elements.Add(new SrgsItem("A nation that has won the World Cup is: "));
// Create the rule for the European nations.
SrgsOneOf oneOfEurope = new SrgsOneOf(new SrgsItem[] {new SrgsItem("England"),
new SrgsItem("France"), new SrgsItem("Germany"), new SrgsItem("Italy")});
SrgsRule ruleEurope = (new SrgsRule("EuropeanNations", new SrgsElement[] {oneOfEurope}));
// Create the rule for the South American nations.
SrgsOneOf oneOfSAmerica = new SrgsOneOf(new SrgsItem[] {new SrgsItem("Argentina"),
new SrgsItem("Brazil"), new SrgsItem("Uruguay")});
SrgsRule ruleSAmerica = (new SrgsRule("SouthAmericanNations", new SrgsElement[] {oneOfSAmerica}));
// Add references to winnerRule for ruleEurope and ruleSAmerica.
winnerRule.Elements.Add(new SrgsOneOf(new SrgsItem[] {(new SrgsItem
(new SrgsRuleRef(ruleEurope))), new SrgsItem(new SrgsRuleRef(ruleSAmerica))}));
// Add all the rules to the document and make winnerRule
// the root rule of the document.
document.Rules.Add(new SrgsRule[] {winnerRule, ruleEurope, ruleSAmerica});
document.Root = winnerRule;
// Create a string object with the path to the file to use.
string srgsDocumentFile = Path.Combine(Path.GetTempPath(), "srgsDocumentFile.xml");
// Create an XmlWriter object and pass the file path.
XmlWriter writer = XmlWriter.Create(srgsDocumentFile);
// Write the contents of the XmlWriter object to an SRGS-compatible XML file.
document.WriteSrgs(writer);
writer.Close();
}