Share via


SecurityElement.SearchForTextOfTag(String) Método

Definición

Busca un elemento secundario por su nombre de etiqueta y devuelve el texto que contiene.

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

Parámetros

tag
String

Etiqueta que se va a buscar en los elementos secundarios.

Devoluciones

Contenido del texto del primer elemento secundario con el valor de etiqueta especificado.

Excepciones

tag es null.

Ejemplos

En el SearchForTextOfTag código siguiente se muestra el uso del método para buscar un elemento secundario por su nombre de etiqueta y devolver el texto contenido. Este ejemplo de código es parte de un ejemplo más grande proporcionado para la clase SecurityElement.

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

Comentarios

Este método es equivalente a lo siguiente:

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

Con XML como se indica a continuación, SearchForTextOfTag("second") devolvería "text2".

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

Se aplica a