public static bool ParseTemplate(string path, out Template template, out ErrorCollector errorCollector) { errorCollector = new ErrorCollector(); template = new Template(); try { using (XmlReader xmlReader = XmlReader.Create(path, new XmlReaderSettings() { ConformanceLevel = ConformanceLevel.Fragment })) { xmlReader.Read(); while (xmlReader.NodeType != XmlNodeType.None && (xmlReader.NodeType != XmlNodeType.Element || xmlReader.Name != "Template")) { xmlReader.Read(); } if (xmlReader.NodeType == XmlNodeType.None) { errorCollector.AddError("Invalid Xml-structure!"); return(false); } if (!xmlReader.ReadToDescendant("TemplateInfo")) { errorCollector.AddError("<TemplateInfo> not found!"); return(false); } XElement infoElement = XElement.ReadFrom(xmlReader) as XElement; if (infoElement == null || infoElement.Name != "TemplateInfo") { errorCollector.AddError("<TemplateInfo>: invalid Xml-structure!"); return(false); } template.info = ReadInfo(infoElement, errorCollector); if (!xmlReader.ReadToNextSibling("Globals")) { errorCollector.AddError("<Globals> not found!"); return(false); } XElement globalElement = XElement.ReadFrom(xmlReader) as XElement; if (globalElement == null || globalElement.Name != "Globals") { errorCollector.AddError("<Globals>: invalid Xml-structure!"); return(false); } foreach (XElement ele in globalElement.Elements()) { if (ele.Name == "Filters") { template.globalFilters = ReadElementGroup(ele, ReadFilter, errorCollector); } else if (ele.Name == "Actions") { template.globalActions = ReadElementGroup(ele, ReadAction, errorCollector); } else { errorCollector.AddXmlUnkownEleError(ele, globalElement); } } if (!xmlReader.ReadToNextSibling("Pages")) { errorCollector.AddError("<Pages> not found!"); return(false); } template.pages = GetElementGroupList(StreamChildElements(xmlReader), "Page", ReadPage, errorCollector); ReplaceNamedSdcMinObsAlternatives(template.pages, template.info.sdcMinObsAlternatives, errorCollector); } return(!errorCollector.HasErrors()); } catch (Exception exception) { errorCollector.AddError(exception.Message); return(false); } }