private XMLBlock ParseBlockXml(XmlNode node) { /*bool alias = false; * if(node.Attributes["alias"] != null && node.Attributes["alias"].Value.Equals("true", StringComparison.InvariantCultureIgnoreCase)) * alias = true;*/ XMLBlock b = new XMLBlock(node.Attributes["name"].Value); foreach (XmlNode n in node.ChildNodes) { switch (n.Name) { case "block": b.AddBlock(ParseBlockXml(n)); break; case "parameter": b.AddParameter(ParseParameterXml(n)); break; case "required": b.SetRequired(n.InnerText.Trim()); break; } } return(b); }
public bool Match(XMLBlock x, List <XMLParameter> xassums) { if (exists == false || xml != null || x.Name != this.type.ToLower()) { return(false); } xml = x; List <ValidationError> localErrors = new List <ValidationError>(); List <XMLParameter> localXParameters = new List <XMLParameter>(); if (!ParseAlternate(x, xassums, localErrors, localXParameters)) { if (x.Alternates.Count > 0) { bool found = false; foreach (XMLBlock x2 in x.Alternates) { List <ValidationError> localErrors2 = new List <ValidationError>(); List <XMLParameter> localXParameters2 = new List <XMLParameter>(); bool altMatch = ParseAlternate(x2, xassums, localErrors2, localXParameters2); if (altMatch || localErrors2.Count < localErrors.Count) { xml = x2; localErrors = localErrors2; localXParameters = localXParameters2; found = altMatch; if (found) { break; } } } if (!found) { valid = false; errors.AddRange(localErrors); } } else { errors.AddRange(localErrors); valid = false; } } foreach (XMLParameter p in localXParameters) { if (!xparameters.Contains(p)) { xparameters.Add(p); } } return(true); }
public void Add(XMLBlock b) { if (alternates == null) { alternates = new List <XMLBlock>(); } alternates.Add(b); }
public XMLParser(string file) { filepath = file; //references = new List<string>(); XmlReaderSettings readerSettings = new XmlReaderSettings(); readerSettings.IgnoreWhitespace = true; readerSettings.IgnoreComments = true; readerSettings.CheckCharacters = true; readerSettings.CloseInput = true; readerSettings.IgnoreProcessingInstructions = false; readerSettings.ValidationFlags = System.Xml.Schema.XmlSchemaValidationFlags.None; readerSettings.ValidationType = ValidationType.None; XmlDocument xd = new XmlDocument(); xd.Load(XmlReader.Create(new FileStream(filepath, FileMode.Open), readerSettings)); XmlNode root = xd.ChildNodes[1]; XmlNode defs = null /*, refs = null*/, assums = null; foreach (XmlNode n in root.ChildNodes) { if (n.Name == "definitions") { defs = n; } //if (n.Name == "references") refs = n; if (n.Name == "assumptions") { assums = n; } } if (assums != null) { xparams = new List <XMLParameter>(); foreach (XmlNode n in assums.ChildNodes) { xparams.Add(ParseParameterXml(n)); } } if (defs != null) { xblocks = new List <XMLBlock>(); foreach (XmlNode n in defs.ChildNodes) { bool found = false; XMLBlock b = ParseBlockXml(n); foreach (XMLBlock b2 in xblocks) { if (b2.Name == b.Name) { b2.Alternates.Add(b); found = true; break; } } if (!found) { xblocks.Add(b); } } } /*if (refs != null) * { * foreach (XmlNode n in refs.ChildNodes) * { * if (n.Name == "entry") * references.Add(n.InnerText.Trim()); * } * }*/ }
public void AddBlock(XMLBlock b) { blocks.Add(b); }
private bool ParseAlternate(XMLBlock x, List <XMLParameter> xassums, List <ValidationError> localErrors, List <XMLParameter> localXParameters) { if (!exists) { return(false); } bool currValid = true; localXParameters.Clear(); localErrors.Clear(); foreach (INIParameter p in parameters) { p.Clear(); foreach (XMLParameter xp in x.Parameters) { if (p.Match(xp)) { if (!localXParameters.Contains(xp)) { localXParameters.Add(xp); } else if ((xp.Behavior & XMLParameter.XBehavior.REPEATABLE) != XMLParameter.XBehavior.REPEATABLE) { p.Errors.Add(new ValidationError("Parameter '" + p.Name + "' is already defined.", ValidationError.XSeverity.WARNING, ValidationError.XType.CONFLICT_ERROR)); } if (p.Errors != null) { localErrors.AddRange(p.Errors); } } } if (xassums != null && !p.Matched) { foreach (XMLParameter xp in xassums) { if (p.Match(xp)) { if (!localXParameters.Contains(xp)) { localXParameters.Add(xp); } else if ((xp.Behavior & XMLParameter.XBehavior.REPEATABLE) != XMLParameter.XBehavior.REPEATABLE) { p.Errors.Add(new ValidationError("Parameter '" + p.Name + "' is already defined.", ValidationError.XSeverity.WARNING, ValidationError.XType.CONFLICT_ERROR)); } if (p.Errors != null) { localErrors.AddRange(p.Errors); } } } } currValid = currValid && p.Valid; } foreach (XMLParameter xp in x.Parameters) { if ((xp.Behavior & XMLParameter.XBehavior.REQUIRED) == XMLParameter.XBehavior.REQUIRED && !localXParameters.Contains(xp)) { localErrors.Add(new ValidationError("Parameter '" + xp.Name + "' is missing.", ValidationError.XSeverity.ERROR, ValidationError.XType.MISSING_ERROR)); currValid = false; } } foreach (XMLParameter xp in xassums) { if (x.Required.Contains(xp.Name) && !localXParameters.Contains(xp)) { localErrors.Add(new ValidationError("Parameter '" + xp.Name + "' is missing.", ValidationError.XSeverity.ERROR, ValidationError.XType.MISSING_ERROR)); currValid = false; } } return(currValid); }