HtmlElementCollection Klasa

Definicja

Definiuje kolekcję HtmlElement obiektów.

public ref class HtmlElementCollection sealed : System::Collections::ICollection
public sealed class HtmlElementCollection : System.Collections.ICollection
type HtmlElementCollection = class
    interface ICollection
    interface IEnumerable
Public NotInheritable Class HtmlElementCollection
Implements ICollection
Dziedziczenie
HtmlElementCollection
Implementuje

Przykłady

Poniższy przykład kodu używa HtmlElementCollection obiektów do wydrukowania tekstowej reprezentacji modelu obiektów dokumentów (DOM) strony.

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());
}
Private Sub PrintDomBegin()
    If (WebBrowser1.Document IsNot Nothing) Then
        Dim ElemColl As HtmlElementCollection

        Dim Doc As HtmlDocument = WebBrowser1.Document
        If (Not (Doc Is Nothing)) Then
            ElemColl = Doc.GetElementsByTagName("HTML")
            Dim Str As String = PrintDom(ElemColl, New System.Text.StringBuilder(), 0)

            WebBrowser1.DocumentText = Str
        End If
    End If
End Sub

Private Function PrintDom(ByVal ElemColl As HtmlElementCollection, ByRef ReturnStr As System.Text.StringBuilder, ByVal Depth As Integer) As String
    Dim Str As New System.Text.StringBuilder()

    For Each Elem As HtmlElement In ElemColl
        Dim ElemName As String

        ElemName = Elem.GetAttribute("ID")
        If (ElemName Is Nothing Or ElemName.Length = 0) Then
            ElemName = Elem.GetAttribute("name")
            If (ElemName Is Nothing Or ElemName.Length = 0) Then
                ElemName = "<no name>"
            End If
        End If

        Str.Append(CChar(" "), Depth * 4)
        Str.Append(ElemName & ": " & Elem.TagName & "(Level " & Depth & ")")
        ReturnStr.AppendLine(Str.ToString())

        If (Elem.CanHaveChildren) Then
            PrintDom(Elem.Children, ReturnStr, Depth + 1)
        End If

        Str.Remove(0, Str.Length)
    Next

    PrintDom = ReturnStr.ToString()
End Function

Właściwości

Count

Pobiera liczbę elementów w kolekcji.

Item[Int32]

Pobiera element z kolekcji, określając jej indeks liczbowy.

Item[String]

Pobiera element z kolekcji, określając jego nazwę.

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetElementsByName(String)

Pobiera kolekcję elementów według ich nazwy.

GetEnumerator()

Zwraca moduł wyliczający, który iteruje po kolekcji.

GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

ICollection.CopyTo(Array, Int32)

Kopiuje elementy kolekcji do obiektu Array, zaczynając od określonego Array indeksu.

ICollection.IsSynchronized

Pobiera wartość wskazującą, czy dostęp do elementu HtmlElementCollection jest synchronizowany (bezpieczny wątk).

ICollection.SyncRoot

Pobiera obiekt, który może służyć do synchronizowania dostępu do kolekcji.

Metody rozszerzania

Cast<TResult>(IEnumerable)

Rzutuje elementy elementu IEnumerable na określony typ.

OfType<TResult>(IEnumerable)

Filtruje elementy IEnumerable elementu na podstawie określonego typu.

AsParallel(IEnumerable)

Umożliwia równoległość zapytania.

AsQueryable(IEnumerable)

Konwertuje element IEnumerable na .IQueryable

Dotyczy