/// <summary> /// Creates a grammar file representing all of the main grammars of the grammar providers /// to the file requested. /// </summary> /// <param name="fileToSaveTo">File to save the main grammar to.</param> public void UpdateMainGrammarFile(String fileToSaveTo) { List <String> rules = new List <string>(); List <XmlElement> elements = new List <XmlElement>(); // Add grammars from all of our grammar providers. foreach (GrammarProvider provider in _grammarProviders) { if (provider.MainGrammar != null) { rules.Add(provider.MainGrammar.RuleName); elements.AddRange(provider.MainGrammar.Rules); } } // Add utility rules. foreach (String fileName in _utilityFiles) { XmlDocument fileDoc = new XmlDocument(); fileDoc.Load(fileName); foreach (XmlElement element in fileDoc.LastChild.ChildNodes) { elements.Add(element); } } XmlDocument doc = new XmlDocument(); doc.AppendChild(doc.CreateNode(XmlNodeType.XmlDeclaration, "", "")); XmlElement grammar = GrammarUtility.CreateElement(doc, "grammar", new Dictionary <String, String> { { "version", "1.0" }, { "xml:lang", "en-US" }, { "mode", "voice" }, { "root", "overallCommand" }, { "tag-format", "semantics/1.0" }, }); XmlElement overallRule = GrammarUtility.CreateElement(doc, "rule", new Dictionary <String, String> { { "id", "overallCommand" }, { "scope", "public" }, }); XmlElement samiRule = GrammarUtility.CreateElement(doc, "item", new Dictionary <String, String>()); samiRule.InnerText = "Sammie"; overallRule.AppendChild(samiRule); overallRule.AppendChild(GrammarUtility.CreateListOfRuleRefs(doc, rules)); grammar.AppendChild(overallRule); GrammarUtility.CopyElementsToNewRule(grammar, elements); doc.AppendChild(grammar); doc.Save(fileToSaveTo); }