Share via


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( L"destroytime" );
string storedDestroyTime =
    localXmlElement.SearchForTextOfTag("destroytime");
Dim storedDestroyTime As String = localXmlElement.SearchForTextOfTag("destroytime")

注解

此方法等效于以下内容:

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

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

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

适用于