Bloom.Book.HtmlDom.FindChildWithClass C# (CSharp) Method

FindChildWithClass() public static method

Find the first child of parent that has the specified class as (one of) its classes.
public static FindChildWithClass ( XmlElement parent, string classVal ) : XmlElement
parent System.Xml.XmlElement
classVal string
return System.Xml.XmlElement
        public static XmlElement FindChildWithClass(XmlElement parent, string classVal)
        {
            // Can probably be done with xpath ./*[contains(concat(" ", normalize-space(@class), " "), " classVal ")]
            // (plus something to get the first one).
            // But I'm more confident of this version and suspect it might be faster for such a simple case.
            foreach(var node in parent.ChildNodes)
            {
                var elt = node as XmlElement;
                if(elt == null)
                    continue;
                var eltClass = " " + GetAttributeValue(elt, "class") + " ";
                if(eltClass.Contains(" " + classVal + " "))
                    return elt;
            }
            return null;
        }