SecurityElement.SearchForTextOfTag(String) Метод

Определение

Выполняет поиск дочернего элемента по имени тега и возвращает содержащийся в элементе текст.

public:
 System::String ^ SearchForTextOfTag(System::String ^ tag);
public string? SearchForTextOfTag (string tag);
public string SearchForTextOfTag (string tag);
member this.SearchForTextOfTag : string -> string
Public Function SearchForTextOfTag (tag As String) As String

Параметры

tag
String

Тег, для которого нужно выполнить поиск среди дочерних элементов.

Возвращаемое значение

String

Текстовое содержимое первого дочернего элемента с указанным значением тега.

Исключения

tag имеет значение null.

Примеры

В следующем коде показано использование SearchForTextOfTag метода для поиска дочернего элемента по имени тега и возврата содержащегося текста. Этот пример кода является частью большого примера, приведенного для SecurityElement класса.

String^ storedDestroyTime = localXmlElement->SearchForTextOfTag( L"destroytime" );
string storedDestroyTime =
    localXmlElement.SearchForTextOfTag("destroytime");
Dim storedDestroyTime As String = localXmlElement.SearchForTextOfTag("destroytime")

Комментарии

Этот метод эквивалентен следующему:

String^ SearchForTextOfTag(String^ tag)
{
    SecurityElement^ element = this->SearchForChildByTag(tag);
    return element->Text;
}
string SearchForTextOfTag(string tag)
{
    SecurityElement element = this.SearchForChildByTag(tag);
    return element.Text;
}
Public Function SearchForTextOfTag(ByVal tag As String) As String
    Dim element As SecurityElement = MyClass.SearchForChildByTag(tag)
    Return element.Text
End Function

При использовании XML, как показано ниже, SearchForTextOfTag("second") будет возвращено «текст2».

<thetag A="123" B="456" C="789"> <first>text1</first>  
    <second>text2</second></thetag>  

Применяется к