HtmlElementCollection Класс
Определение
Определяет коллекцию объектов HtmlElement.Defines a collection of HtmlElement objects.
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 (DOM) страницы.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());
}
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 |
Получает количество элементов коллекции.Gets the number of elements in the collection. |
Item[Int32] |
Получает элемент из коллекции путем указания его числового индекса.Gets an item from the collection by specifying its numerical index. |
Item[String] |
Получает элемент из коллекции путем указания его имени.Gets an item from the collection by specifying its name. |
Методы
Equals(Object) |
Определяет, равен ли указанный объект текущему объекту.Determines whether the specified object is equal to the current object. (Унаследовано от Object) |
GetElementsByName(String) |
Возвращает коллекцию элементов посредством использования их имени.Gets a collection of elements by their name. |
GetEnumerator() |
Возвращает перечислитель, который осуществляет итерацию по коллекции.Returns an enumerator that iterates through a collection. |
GetHashCode() |
Служит хэш-функцией по умолчанию.Serves as the default hash function. (Унаследовано от Object) |
GetType() |
Возвращает объект Type для текущего экземпляра.Gets the Type of the current instance. (Унаследовано от Object) |
MemberwiseClone() |
Создает неполную копию текущего объекта Object.Creates a shallow copy of the current Object. (Унаследовано от Object) |
ToString() |
Возвращает строку, представляющую текущий объект.Returns a string that represents the current object. (Унаследовано от Object) |
Явные реализации интерфейса
ICollection.CopyTo(Array, Int32) |
Копирует элементы коллекции в Array начиная с определенного индекса в Array.Copies the elements of the collection to an Array, starting at a particular Array index. |
ICollection.IsSynchronized |
Возвращает значение, показывающее, является ли доступ к коллекции HtmlElementCollection синхронизированным (потокобезопасным).Gets a value indicating whether access to the HtmlElementCollection is synchronized (thread safe). |
ICollection.SyncRoot |
Возвращает объект, который можно использовать для синхронизации доступа к коллекции.Gets an object that can be used to synchronize access to the collection. |
Методы расширения
Cast<TResult>(IEnumerable) |
Приводит элементы объекта IEnumerable к заданному типу.Casts the elements of an IEnumerable to the specified type. |
OfType<TResult>(IEnumerable) |
Выполняет фильтрацию элементов объекта IEnumerable по заданному типу.Filters the elements of an IEnumerable based on a specified type. |
AsParallel(IEnumerable) |
Позволяет осуществлять параллельный запрос.Enables parallelization of a query. |
AsQueryable(IEnumerable) |
Преобразовывает коллекцию IEnumerable в объект IQueryable.Converts an IEnumerable to an IQueryable. |