/// <summary> /// Validates all the elements registered at construction using the /// <see cref="NodeIndex"/> to locate them as quickly as possible. /// </summary> /// <param name="nodeIndex">The <see cref="NodeIndex"/> of the test document.</param> /// <param name="errorHandler">The <see cref="ValidationErrorHandler"/> used to report issues.</param> /// <returns><c>true</c> if the code values pass the checks, <c>false</c> /// otherwise.</returns> protected override bool Validate(NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { bool result = true; for (int index = 0; index < elementNames.Length; ++index) { XmlNodeList list = nodeIndex.GetElementsByName(elementNames [index]); if (parentNames == null) { result &= Validate(list, errorHandler); } else { MutableNodeList targets = new MutableNodeList(); foreach (XmlElement context in list) { XmlNode parent = context.ParentNode; if ((parent.NodeType == XmlNodeType.Element) && parent.LocalName.Equals(parentNames [index])) { targets.Add(context); } } result &= Validate(targets, errorHandler); } } return(result); }
/// <summary> /// Returns a <see cref="XmlNodeList"/> containing all the elements /// defined in the <see cref="NodeIndex"/> that match the context /// specification. /// </summary> /// <param name="nodeIndex">A <see cref="NodeIndex"/> for the test document.</param> /// <returns>A <see cref="XmlNodeList"/> containing all the matching /// <see cref="XmlElement"/> instances, if any.</returns> public XmlNodeList GetMatchingElements(NodeIndex nodeIndex) { if (parentNames == null) { return(nodeIndex.GetElementsByName(elementNames)); } else { MutableNodeList result = new MutableNodeList(); for (int index = 0; index < elementNames.Length; ++index) { XmlNodeList matches = nodeIndex.GetElementsByName(elementNames [index]); if (parentNames [index] == null) { result.AddAll(matches); } else { for (int count = 0; count < matches.Count; ++count) { XmlElement element = (XmlElement)matches [count]; XmlNode parent = element.ParentNode; if (parent.NodeType == XmlNodeType.Element) { if (parent.LocalName.Equals(parentNames [index])) { result.Add(element); } } } } } return(result); } }