Redigera

Dela via


SecurityElement.SearchForTextOfTag(String) Method

Definition

Finds a child by its tag name and returns the contained text.

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

Parameters

tag
String

The tag for which to search in child elements.

Returns

The text contents of the first child element with the specified tag value.

Exceptions

tag is null.

Examples

The following code shows the use of the SearchForTextOfTag method to find a child by its tag name and return the contained text. This code example is part of a larger example provided for the SecurityElement class.

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

Remarks

This method is equivalent to the following:

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

With XML as follows, SearchForTextOfTag("second") would return "text2".

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

Applies to