อ่านในภาษาอังกฤษ แก้ไข

แชร์ผ่าน


SecurityElement.SearchForTextOfTag(String) Method

Definition

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

C#
public string? SearchForTextOfTag(string tag);
C#
public string SearchForTextOfTag(string tag);

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.

C#
string storedDestroyTime =
    localXmlElement.SearchForTextOfTag("destroytime");

Remarks

This method is equivalent to the following:

C#
string SearchForTextOfTag(string tag)
{
    SecurityElement element = this.SearchForChildByTag(tag);
    return element.Text;
}

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

ผลิตภัณฑ์ เวอร์ชัน
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1