HtmlElementCollection 클래스

정의

HtmlElement 개체의 컬렉션을 정의합니다.

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
상속
HtmlElementCollection
구현

예제

다음 코드 예제에서는 HtmlElementCollection 페이지의 문서 개체 모델 (DOM)의 텍스트 표현을 출력 하는 개체입니다.

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

속성

Count

컬렉션의 요소 수를 가져옵니다.

Item[Int32]

숫자 인덱스를 지정하여 컬렉션에서 항목을 가져옵니다.

Item[String]

이름을 지정하여 컬렉션에서 항목을 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetElementsByName(String)

이름으로 요소의 컬렉션을 가져옵니다.

GetEnumerator()

컬렉션을 반복하는 열거자를 반환합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

ICollection.CopyTo(Array, Int32)

특정 Array 인덱스부터 시작하여 컬렉션의 요소를 Array에 복사합니다.

ICollection.IsSynchronized

HtmlElementCollection에 대한 액세스가 동기화되어 스레드로부터 안전하게 보호되는지를 나타내는 값을 가져옵니다.

ICollection.SyncRoot

컬렉션에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상