Sdílet prostřednictvím


SrgsDocument.WriteSrgs(XmlWriter) Metoda

Definice

Zapíše obsah SrgsDocument objektu do souboru gramatiky ve formátu XML, který odpovídá specifikaci gramatiky rozpoznávání řeči (SRGS) verze 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)

Parametry

srgsGrammar
XmlWriter

Ta XmlWriter , která se používá k zápisu SrgsDocument instance.

Výjimky

srgsGrammar je null.

Příklady

Následující příklad vytvoří SrgsDocument objekt a poté vytvoří veřejné pravidlo s názvem winnerRule . Pak vytvoří SrgsItem , který se skládá z řetězce "A", který získal světový konvičku: ", a přidá tuto položku do Elements Vlastnosti pravidla. Příklad následně vytvoří dvě další pravidla ( ruleEurope a ruleSAmerica ), z nichž každý je SrgsOneOf objekt, který obsahuje tři SrgsItem objekty. Následně SrgsOneOf je vytvořen jiný objekt, který obsahuje SrgsRuleRef objekty, které odkazují na ruleEurope a ruleSAmerica . Nový SrgsOneOf objekt je poté přidán do Elements vlastnosti winnerRule . Po tomto případě budou všechna tři pravidla ( winnerRule , a ruleEurope ruleSAmerica ) přidána do Rules vlastnosti SrgsDocument . Nakonec příklad vytvoří prázdný soubor XML a instanci XmlWriter . WriteSrgsMetoda používá XmlWriter instanci k zápisu obsahu do SrgsDocument souboru 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();  
}  

Platí pro