Share via


SrgsDocument.WriteSrgs(XmlWriter) メソッド

定義

音声認識文法仕様 (SRGS) バージョン 1.0 に準拠する XML 形式の文法ファイルに SrgsDocument オブジェクトの内容を書き込みます。

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)

パラメーター

srgsGrammar
XmlWriter

XmlWriter インスタンスの書き込みに使用する SrgsDocument

例外

srgsGrammarnullです。

次の例では、 SrgsDocument オブジェクトを作成し、という名前のパブリックルールを作成し winnerRule ます。 次に、 SrgsItem "ワールドカップを獲得した国" という文字列で構成されるを作成し、この項目を Elements ルールのプロパティに追加します。 この例では、さらに2つのルール ( ruleEuroperuleSAmerica ) を作成します。各ルールは、 SrgsOneOf 3 つのオブジェクトを含むオブジェクトです SrgsItem 。 その後、 SrgsOneOf SrgsRuleRef とを参照するオブジェクトを含む別のオブジェクトが作成され ruleEurope ruleSAmerica ます。 その後、新しい SrgsOneOf オブジェクトがのプロパティに追加され Elements winnerRule ます。 その後、3つのすべての規則 ( winnerRuleruleEurope 、および ruleSAmerica ) がのプロパティに追加され Rules SrgsDocument ます。 最後に、空の XML ファイルとのインスタンスを作成し XmlWriter ます。 メソッドは、インスタンスを使用して WriteSrgs XmlWriter 、の内容を SrgsDocument 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();  
}  

適用対象