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

String

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

Excepciones

tag es null.

Ejemplos

El código siguiente muestra el uso del método para buscar un elemento secundario por su nombre SearchForTextOfTag de etiqueta y devolver el texto contenido. Este ejemplo de código forma parte de un ejemplo mayor proporcionado para la SecurityElement clase .

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 muestra a SearchForTextOfTag("second") continuación, devolvería "text2".

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

Se aplica a