public static void GetImageArrayList(HtmlNodeCollection nodes, ref IList imgArrayList) { //ListItem li = null; foreach (HtmlNode t in nodes) { if (t is HtmlElement) { if (IsProcessElement((HtmlElement)t)) { foreach (HtmlAttribute arrt in ((HtmlElement)t).Attributes) { if (arrt.Value != null) { if (arrt.Value.ToLower().IndexOf(".jpg") > 0 || arrt.Value.ToLower().IndexOf(".gif") > 0) { imgArrayList.Add(arrt.Value); } } } } } if (t is HtmlElement) { GetImageArrayList(((HtmlElement)t).Nodes, ref imgArrayList); } } }
/// <summary> /// This constructs a new HTML element with the specified tag name. /// </summary> /// <param name="name">The name of this element</param> public HtmlElement(string name) { mNodes = new HtmlNodeCollection( this ); mAttributes = new HtmlAttributeCollection(this); mName = name; mIsTerminated = false; }
/// <summary> /// This will search though this collection of nodes for all elements with the /// specified name. If you want to search the subnodes recursively, you should /// pass True as the parameter in searchChildren. This search is guaranteed to /// return nodes in the order in which they are found in the document. /// </summary> /// <param name="name">The name of the element to find</param> /// <param name="searchChildren">True if you want to search sub-nodes, False to /// only search this collection.</param> /// <returns>A collection of all the nodes that macth.</returns> public HtmlNodeCollection FindByName(string name,bool searchChildren) { HtmlNodeCollection results = new HtmlNodeCollection(null); foreach( HtmlNode node in base.List ) { if( node is HtmlElement ) { if( ( (HtmlElement)node ).Name.ToLower().Equals( name.ToLower() ) ) { results.Add( node ); } if( searchChildren ) { foreach( HtmlNode matchedChild in ( (HtmlElement)node ).Nodes.FindByName( name , searchChildren ) ) { results.Add( matchedChild ); } } } } return results; }
public HtmlNodeCollection FindByAttributeNameValue(string attributeName,string attributeValue,bool searchChildren) { HtmlNodeCollection results = new HtmlNodeCollection(null); foreach( HtmlNode node in base.List ) { if( node is HtmlElement ) { foreach( HtmlAttribute attribute in ((HtmlElement)node).Attributes ) { if( attribute.Name.ToLower().Equals( attributeName.ToLower() ) ) { if( attribute.Value.ToLower().Equals( attributeValue.ToLower() ) ) { results.Add( node ); } break; } } if( searchChildren ) { foreach( HtmlNode matchedChild in ( (HtmlElement)node ).Nodes.FindByAttributeNameValue( attributeName , attributeValue , searchChildren ) ) { results.Add( matchedChild ); } } } } return results; }
/// <summary> /// This will create a new document object by parsing the HTML specified. /// </summary> /// <param name="html">The HTML to parse.</param> internal HtmlDocument(string html,bool wantSpaces) { HtmlParser parser = new HtmlParser(); parser.RemoveEmptyElementText = !wantSpaces; mNodes = parser.Parse( html ); }