Ejemplo n.º 1
0
 /// <summary>Returns first node that match the given matcher (Func that should return true if it matches)</summary>
 public static XmlNode Node(this XmlNode node, XmlNodeMatcher matcher)
 {
     if (node == null)
     {
         return(null);
     }
     return(node.Nodes(matcher).FirstOrDefault());
 }
Ejemplo n.º 2
0
        /// <summary>Returns a List of XmlNode matching the given matcher.  If onlyFindOne is true, we stop looking after we find 1 match.</summary>
        public static List <XmlNode> Nodes(this XmlNode node, XmlNodeMatcher matcher, bool onlyFindOne)
        {
            var nodes = new List <XmlNode>();

            if (node == null)
            {
                return(nodes);
            }
            foreach (XmlNode child in node.ChildNodes)
            {
                if (matcher.Invoke(child))
                {
                    nodes.Add(child);
                    if (onlyFindOne)
                    {
                        break;
                    }
                }

                nodes.AddRange(child.Nodes(matcher));

                if (onlyFindOne && nodes.Count > 0)
                {
                    break;
                }
            }

            if (onlyFindOne && nodes.Count > 1)
            {
                return new List <XmlNode> {
                           nodes.First()
                }
            }
            ;
            else
            {
                return(nodes);
            }
        }
Ejemplo n.º 3
0
 /// <summary>Returns all nodes (searches recursively) that match the given matcher (Func that should return true if it matches)</summary>
 public static List <XmlNode> Nodes(this XmlNode node, XmlNodeMatcher matcher)
 {
     return(node.Nodes(matcher, false));
 }