SecurityElement.SearchForTextOfTag(String) Méthode

Définition

Recherche un enfant par son nom de balise et retourne le texte qu'il contient.

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

Paramètres

tag
String

Balise à rechercher dans les éléments enfants.

Retours

String

Texte contenu dans le premier élément enfant avec la valeur de balise spécifiée.

Exceptions

tag a la valeur null.

Exemples

Le code suivant illustre l’utilisation de la SearchForTextOfTag méthode pour rechercher un enfant par son nom de balise et retourner le texte contenu. Cet exemple de code fait partie d’un exemple plus complet fourni pour la SecurityElement classe.

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

Remarques

Cette méthode est équivalente à ce qui suit :

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

Avec XML comme suit, SearchForTextOfTag("second") retourne « Text2 ».

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

S’applique à