/// <summary> /// check to see if node meets all the conditions /// </summary> /// <param name="node"></param> /// <param name="ignore"></param> /// <returns></returns> private bool conditionMet(XmlNode node, IgnoreElement ignore, XmlNamespaceManager nsmgr) { try { foreach (var condition in ignore.ElementConditions) { XmlNodeList nodes = node.SelectNodes(condition, nsmgr); if ((nodes == null) || nodes.Count <= 0) { return false; } } return true; } catch (Exception ex) { #if DEBUG Trace.WriteLineIf(T_Phases.Enabled, "error: " + ex.Message + ". Ignore condition failed. possible bad xpath format: " + ignore.ElementXpath); #endif return false; } }
/// <summary> /// load the ignore config file into memory /// </summary> /// <param name="ignoreFile"></param> /// <returns></returns> private List<IgnoreElement> LoadIgnoreFile(string ignoreFile) { var ignoredElements = new List<IgnoreElement>(); XmlDocument doc = new XmlDocument(); doc.Load(ignoreFile); XmlNodeList nodes = doc.SelectNodes("/ignoreElements/ignoreElement"); foreach (XmlNode ignoreNode in nodes) { var ignoreElementXpath = ignoreNode.SelectSingleNode("elementXpath").InnerText; var ignoreEntry = new IgnoreElement(ignoreElementXpath); var conditions = ignoreNode.SelectNodes("conditions/condition"); if (conditions != null && conditions.Count > 0) { foreach (XmlNode condition in conditions) { ignoreEntry.ElementConditions.Add(condition.InnerText); } } var namespaces = ignoreNode.SelectNodes("namespaces/namespace"); if (namespaces != null && namespaces.Count > 0) { foreach (XmlNode ns in namespaces) { ignoreEntry.ElementNamespaces.Add(new IgnoreElement.XmlNamespace { Prefix = ns.SelectSingleNode("prefix").InnerText, Value = ns.SelectSingleNode("value").InnerText }); } } ignoredElements.Add(ignoreEntry); } return ignoredElements; }