SrgsDocument.WriteSrgs(XmlWriter) Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Nesnenin SrgsDocument içeriğini Konuşma Tanıma Dil Bilgisi Belirtimi (SRGS) Sürüm 1.0'a uyan XML biçiminde bir dil bilgisi dosyasına yazar.
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)
Parametreler
- srgsGrammar
- XmlWriter
XmlWriter Örneği yazmak SrgsDocument için kullanılan.
Özel durumlar
srgsGrammar
, null
değeridir.
Örnekler
Aşağıdaki örnek bir SrgsDocument nesne oluşturur ve ardından adlı winnerRule
bir genel kural oluşturur. Ardından "Dünya Kupası'nı kazanan bir ülke: " dizesini içeren bir SrgsItem oluşturur ve bu öğeyi kuralın özelliğine Elements ekler. Örnek daha sonra her biri üç SrgsItem nesne içeren bir SrgsOneOf nesne olan iki kural daha (ruleEurope
ve ruleSAmerica
) oluşturur. Bundan sonra ve ruleSAmerica
öğesine başvuran ruleEurope
nesneleri içeren SrgsRuleRef başka bir SrgsOneOf nesne oluşturulur.
SrgsOneOf Yeni nesne daha sonra özelliğine ElementswinnerRule
eklenir. Bundan sonra, üç kuralın (winnerRule
, ruleEurope
ve ruleSAmerica
) tümü öğesinin Rules özelliğine SrgsDocumenteklenir. Son olarak, örnek boş bir XML dosyası ve örneği XmlWriteroluşturur. yöntemi, WriteSrgs öğesinin XmlWriter içeriğini SrgsDocument XML dosyasına yazmak için örneğini kullanır.
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();
}