SecurityElement.SearchForTextOfTag(String) 方法

定义

按其标记名称查找子级并返回包含的文本。

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

参数

tag
String

要在其中搜索子元素的标记。

返回

具有指定标记值的第一个子元素的文本内容。

例外

tagnull

示例

以下代码演示如何使用 SearchForTextOfTag 该方法按其标记名称查找子级并返回包含的文本。 该代码示例是 SecurityElement 类中的一个较大示例的一部分。

string storedDestroyTime =
    localXmlElement.SearchForTextOfTag("destroytime");
Dim storedDestroyTime As String = localXmlElement.SearchForTextOfTag("destroytime")

注解

此方法等效于以下各项:

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

使用如下所示的 XML, SearchForTextOfTag("second") 将返回“text2”。

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

适用于