HtmlElementCollection Class
.NET Framework 2.0
Note: This class is new in the .NET Framework version 2.0.
Defines a collection of HtmlElement objects.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Assembly: System.Windows.Forms (in system.windows.forms.dll)
The following code example uses HtmlElementCollection objects to print out a textual representation of the Document Object Model (DOM) of a page.
private void PrintDomBegin() { if (webBrowser1.Document != null) { HtmlElementCollection elemColl = null; HtmlDocument doc = webBrowser1.Document; if (doc != null) { elemColl = doc.GetElementsByTagName("HTML"); String str = PrintDom(elemColl, new System.Text.StringBuilder(), 0); webBrowser1.DocumentText = str; } } } private string PrintDom(HtmlElementCollection elemColl, System.Text.StringBuilder returnStr, Int32 depth) { System.Text.StringBuilder str = new System.Text.StringBuilder(); foreach (HtmlElement elem in elemColl) { string elemName; elemName = elem.GetAttribute("ID"); if (elemName == null || elemName.Length == 0) { elemName = elem.GetAttribute("name"); if (elemName == null || elemName.Length == 0) { elemName = "<no name>"; } } str.Append(' ', depth * 4); str.Append(elemName + ": " + elem.TagName + "(Level " + depth + ")"); returnStr.AppendLine(str.ToString()); if (elem.CanHaveChildren) { PrintDom(elem.Children, returnStr, depth + 1); } str.Remove(0, str.Length); } return(returnStr.ToString()); }
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Community Additions
ADD
Show: